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.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Resolved How do you do a dots ray cast in b13?

Discussion in '2022.2 Beta' started by spinaljack, Nov 8, 2022.

  1. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    984
    I'm trying to do a grounded test for my 3d character and all the examples I can find don't work in the latest unity editor.
     
  2. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    984
    Found this code which works:
    Code (CSharp):
    1. public Entity Raycast(float3 RayFrom, float3 RayTo)
    2.    {
    3.        // Set up Entity Query to get PhysicsWorldSingleton
    4.        // If doing this in SystemBase or ISystem, call GetSingleton<PhysicsWorldSingleton>()/SystemAPI.GetSingleton<PhysicsWorldSingleton>() directly.
    5.        EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
    6.  
    7.        EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);
    8.        var collisionWorld = singletonQuery.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;
    9.        singletonQuery.Dispose();
    10.  
    11.        RaycastInput input = new RaycastInput()
    12.        {
    13.            Start = RayFrom,
    14.            End = RayTo,
    15.            Filter = new CollisionFilter()
    16.            {
    17.                BelongsTo = ~0u,
    18.                CollidesWith = ~0u, // all 1s, so all layers, collide with everything
    19.                GroupIndex = 0
    20.            }
    21.        };
    22.  
    23.        RaycastHit hit = new RaycastHit();
    24.        bool haveHit = collisionWorld.CastRay(input, out hit);
    25.        if (haveHit)
    26.        {
    27.            return hit.Entity;
    28.        }
    29.        return Entity.Null;
    30.    }
    Lots of code for just a raycast...