Raycast not working

Options
Hi :D. I would like to know why my raycast system isnt working with Bolt Entities, and how to make it work. Thank you :3




function Update () {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
var hit : RaycastHit;

if (Physics.Raycast(ray, hit, 30)){
Debug.DrawLine(transform.position, hit.point, Color.red);
Debug.Log ("Worked :D");
}
}


Best Answers

Answers

  • Wizzard
    Options
    You need to use BoltNetwork.RaycastAll instead of Physics.Raycast
  • Wizzard said:

    You need to use BoltNetwork.RaycastAll instead of Physics.Raycast

    And what things should I modify of the script above?
  • Look in the Bolt Tutorial for examples
  • stanchion said:

    Look in the Bolt Tutorial for examples

    Which of them?
  • It is included with Bolt when you download it
  • DallasOnFire
    edited September 2015
    Options
    stanchion said:

    It is included with Bolt when you download it

    In here? (https://www.assetstore.unity3d.com/en/#!/content/41330). If so, how is it its file name?. If not, how can I get that tutorial?
  • Please help :(
  • And it got automatically answered. I didnt press anything O.o.
  • It is in the package in the Sample folder
  • Okay @stanchion. I made this 2 scripts in base of the tutorial you talked me about, but im getting this error: IndexOutOfRangeException: Array index is out of range.
    BoltHitboxBodySnapshot.Raycast (Vector3 origin, Vector3 direction, .BoltPhysicsHits hits)
    BoltPhysics.Raycast (Ray ray, .BoltHitboxWorldSnapshot sn)
    BoltPhysics.Raycast (Ray ray, Int32 frame)
    BoltNetwork.RaycastAll (Ray ray, Int32 frame)
    CrosshairTest.OnOwner (.BoltEntity entity) (at Assets/CrosshairTest.cs:25)
    CrosshairTest.Update () (at Assets/CrosshairTest.cs:7)

    Script 01:
    using UnityEngine;
    using System.Collections;

    public class WeaponBase : MonoBehaviour {

    public byte damagePerBullet = 25;
    public int refireRate = 5;
    public int fireFrame;

    public virtual void OnOwner(BoltEntity entity) {

    }

    public virtual void Fx(BoltEntity entity) {

    }
    }


    Script 02:
    using UnityEngine;
    using System.Collections;

    public class CrosshairTest : WeaponBase {

    void Update (){
    OnOwner (transform.parent.GetComponent());
    }

    public override void OnOwner(BoltEntity entity) {
    if (entity.isOwner) {
    Debug.DrawRay(transform.position, transform.rotation * Vector3.forward);

    using (var hits = BoltNetwork.RaycastAll(new Ray(transform.position, transform.rotation * Vector3.forward), 60)) {
    Debug.Log("2");
    for (int i = 0; i < hits.count; ++i) {
    Debug.Log(hits.count);
    var hit = hits.GetHit(i);
    var serializer = hit.body.GetComponent();

    if ((serializer != null)) {
    Debug.Log ("Hi :D");
    }
    }
    }
    }
    }
    }

    Can you please help me? Thank you :D
  • Help please :(
  • DallasOnFire
    edited September 2015
    Options
    stanchion said:

    yes it is included in the sample folder

    Yes, I've already done it. But I made some modifications and im getting the error I mentioned in the comment before.

    Thanks for your patience.
  • stanchion said:

    That error means you are trying to access a member of an array that doesn't exist. I would start with the tutorial code and make small changes at a time until you understand what is going on

    Okay, thank you very much :D. I will keep this post up to date.
  • GanjaRaiders52
    edited December 2020
    Options
    Do u get it to work ? I have the same problem, when i spawn a second entity with hitbox body and hitbox components on every bodypart i cant get andy information trought raycastall. when i shoot him the console say, hit.count is 0 every time is hit count 0. the entity has a character controller but i think its not the reason for my issue cause boltnetwork raycastAll i think only recognize boltnetwork hitboxes.

    Heres the part from the script

    sry that i bump and old thread but its the only thread that describe the same problem like me

    {
    Vector2 rnd = Random.insideUnitCircle * weaponStats.precision;
    Ray ray = new Ray(weaponOrigin.position, _Camera.transform.forward + (_Camera.transform.up * rnd.y)+(_Camera.transform.right*rnd.x));

    //Bolt Raycast
    using (Bolt.LagCompensation.BoltPhysicsHits hits = BoltNetwork.RaycastAll(ray))
    {
    Debug.Log(hits.count);
    for (int hitLayer = 0; hits.count > i; i++)
    {
    Debug.Log(hits.GetHit(i).body.ToString());
    }
    }
    //Unity Raycast
    RaycastHit hit;
  • GanjaRaiders52
    edited December 2020
    Options
    Ok i changed the part with raycastAll to
    using (Bolt.LagCompensation.BoltPhysicsHits hits = BoltNetwork.RaycastAll(ray, BoltNetwork.Frame))
    and now its count every hitbox in one round. And next test play its dont work anymore. one time its has worked i changed to boltnetwork.serverframe since then its not working now i changed back to boltnetwork Frame but nothing change. its really strange ...

    I debugged it and when i shoot 100 shots to the entity its count 100 times 0 and one time 2, one time 3.
    i hit only 5 time the hitbox from 100 shots