I have a parallel job in which I’d like to detect which Entities I hit. Not all entities will have rigidbodies so the following isn’t so useful.
Entity e = physicsWorldSystem.PhysicsWorld.Bodies[hit.RigidBodyIndex].Entity
My job looks something like:
[BurstCompile]
struct ProjectilePhysicsRayJob : IJobForEach<Translation, Projectile>
{
public NativeArray<Unity.Physics.RaycastHit> raycastResultsInJob;
[ReadOnly] public Unity.Physics.CollisionWorld collisionWorldInJob;
public float deltaTime;
public void Execute([ReadOnly] ref Translation position, ref Projectile projectile)
{
Unity.Physics.RaycastInput raycastInput = new Unity.Physics.RaycastInput
{
Start = position.Value,
End = position.Value + (projectile.velocity * deltaTime),
Filter = Unity.Physics.CollisionFilter.Default
};
if (collisionWorldInJob.CastRay(raycastInput, out Unity.Physics.RaycastHit hit))
{
raycastResultsInJob[projectile._tempIdx] = hit;
}
}
}
How can I determine which Entities and/or meshes where hit?