Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved Unity.Physics.Collider.CastRay not working?

Discussion in 'Physics for ECS' started by MNNoxMortem, Mar 10, 2022.

  1. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    A BoxCollider at origin with size 1.0 and identity rotation is not hit by a ray going through the origin from 0,10,0 to 0,-10,0.

    Is this a bug - or am I simply missing something because I am already blind to it?

    Code (CSharp):
    1. using var testCollider = BoxCollider.Create(new BoxGeometry
    2. {
    3.     Center = float3.zero,
    4.     BevelRadius = 0f,
    5.     Orientation = quaternion.identity,
    6.     Size        = new float3(1f, 1f, 1f)
    7. });
    8.  
    9. if (testCollider.Value.CastRay(new RaycastInput
    10.     {
    11.         Start = new float3(0f, 10f, 0f),
    12.         End   = new float3(0f, -10f, 0f)
    13.     }))
    14. {
    15.     this.LogDebug("Hit");
    16. }
    17. else
    18. {
    19.     this.LogDebug("Is this a bug?"); // <- CastRay returns false
    20. }
    Using these versions

    Code (CSharp):
    1. "com.unity.physics": "0.5.1-preview.2",
    2. "com.unity.entities": "0.17.0-preview.42",
    3. "com.unity.mathematics": "1.2.5",
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,673
    You haven't specified a CollisionFilter
     
    MNNoxMortem likes this.
  3. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @tertle You are correct. I assumed, the default is CollisionFilter.Default, but the default sadly is CollisionFilter.Zero.