Is there anyway to make raycast rotate?
For example a car starts and left and right walls are in some distance from it. Then I turn around.
Left and Right raycast should point on the opposite wall, how to do that?
Is there anyway to make raycast rotate?
For example a car starts and left and right walls are in some distance from it. Then I turn around.
Left and Right raycast should point on the opposite wall, how to do that?
If raycasts couldn’t ‘rotate’, they could only ever point in one direction, which wouldn’t be very useful ![]()
As for how to get them pointing in the direction you want them to point in, take a look at the Transform properties ‘right’, ‘up’, and ‘forward’. If you need to raycast in a direction other than that of one of the local-space direction vectors or their negatives, you can use Transform.TransformDirection() to transform an arbitrary direction vector into world space.
Right, good point mate
Vector3 ObjLeft = transform.TransformDirection(Vector3.left);
Vector3 ObjRight = transform.TransformDirection(Vector3.right);
Vector3 ObjForward = transform.TransformDirection(Vector3.forward);
and everything is great
Yup, that’s it
One minor point though. This:
Vector3 ObjLeft = transform.TransformDirection(Vector3.left);
Vector3 ObjRight = transform.TransformDirection(Vector3.right);
Vector3 ObjForward = transform.TransformDirection(Vector3.forward);
Can simply be written as:
Vector3 ObjLeft = -transform.right;
Vector3 ObjRight = transform.right;
Vector3 ObjForward = transform.forward;