I have attempting to create a simple point and click teleportation system for a project I am working on. In order to perform the teleport I want to use a Physics raycast to find the position to move to. However, after experimenting with the code provided on the Unity Physics collision queries page, and the code from the Physics samples project, and my own attempts at implementation, I have been unable to get the the raycast to preform.
Entities
.WithName("LocomotionTeleportation")
.WithoutBurst()
.ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, in Translation translation, in Rotation rotation, in LocomotionTeleportationInputData input, in LocomotionTeleportationData teleportationData) => {
if (input.enableTeleport == 1) {
var startPos = translation.Value;
var endPos = translation.Value + math.forward(rotation.Value) * teleportationData.distance;
var rayInput = new RaycastInput() {
Start = startPos,
End = endPos,
Filter = new CollisionFilter() {
BelongsTo = ~0u,
CollidesWith = ~0u,
GroupIndex = 0
}
};
if (input.engageTeleport == 1) {
bool didCast = collisionWorld.CastRay(rayInput, out var hit);
if (!didCast) {
Debug.Log("Failed to cast ray");
}
Debug.Log(hit.Entity);
}
}
}).Schedule();
No matter what I change about the code, the collisionWorld.CastRay() method never seems to get performed, only ever producing a Debug log stating the failure, as I have defined.