Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question collisionWorld.CastRay hit itself ,but i dont want.just like UnityEngine.Physics.Raycast

Discussion in 'Physics for ECS' started by tianlvzhubao, Jun 3, 2023.

?

collisionWorld.CastRay hit itself ,but i dont want.just like UnityEngine.Physics.Raycast

  1. collisionWorld.CastRay hit itself ,but i dont want.just like UnityEngine.Physics.Raycast

    0 vote(s)
    0.0%
  2. collisionWorld.CastRay hit itself ,but i dont want.just like UnityEngine.Physics.Raycast

    0 vote(s)
    0.0%
  1. tianlvzhubao

    tianlvzhubao

    Joined:
    Jan 1, 2023
    Posts:
    14
    using Unity.Physics;

    bool haveHit = collisionWorld.CastRay(input, out hit);
    if (haveHit)
    {
    return hit.Entity;
    }


    collisionWorld.CastRay hit itself ,but i dont want.just like UnityEngine.Physics.Raycast

    how to set,or i need to use
    bool CastRay(RaycastInput input, ref NativeList<RaycastHit> allHits)
    {
    return QueryWrappers.RayCast(in this, input, ref allHits);
    }

    and forloop allHits that look if it's length is >2
    this ray is always begin from collider player
     
  2. KANIYO

    KANIYO

    Joined:
    Nov 12, 2020
    Posts:
    29
    I use the following code to get the AABB of my own collider and use RayCast from outside my own collider.

    Code (CSharp):
    1. PhysicsCollider.ValueRO.Value.CalculateAabb()
    2.  
    I hope this helps.