I need to fire a raycast from my player, which is a spaceship, EXACTLY right or left.
Not right or left relative to the player’s orientation, but right or left relative to the world. The player’s orientation changes a lot, so when I shoot a ray right or left, using Vector3.right or Vector3.left, it’s very often pointing downward or upward.
Is there a way I can fire a ray that totally disregards the player’s rotation, even though it’s firing from the player?
Here’s the relevant portion of the code:
Vector3 raycastDirection;
if (movingRight)
raycastDirection = Vector3.right;
else
raycastDirection = Vector3.left;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(raycastDirection), out hit, Mathf.Infinity, ground))
{
Debug.DrawLine(transform.position, hit.point, Color.red);
proximityDistance = hit.distance;
}
Or maybe a better question is, "exactly right" from who's point of view?
– dstearsFrom the world's point of view is what I'm trying for.
– MerlinsMaster