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.

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,797
    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.
     
    ammills11 likes this.