- Home /
How do I make sure that a ray ALWAYS points straight down?
hey i am having a problem that is related to raycasting. I have a ray that is attached to a camera, to make sure that it is always at the correct distance to the ground. However, when I rotate the camera, so does the ray. I thougt that transform.up was global, but I must have misread, since script reference says world space. So anyone know how to make sure the ray is always pointing directly down , global space?
ray = new Ray(transform.position, transform.up*-1);
Physics.Raycast(ray, out hit);
print("Distance to ground is: " + hit.distance);
Answer by hellcats · May 29, 2011 at 07:42 PM
transform.up is in global space, but it is the "up" direction of the transform. What you want is simply Vector3.up.
Answer by Anxo · May 29, 2011 at 07:43 PM
instead of using transform.up try Vector3.up*-1
This also, I can only give one accept, and hellcats was first :/
Your answer
Follow this Question
Related Questions
3rd person 3D aiming 1 Answer
LOS Rotation with constant width 0 Answers
Create new rays, based on forward but rotated 1 Answer
How to detect object by rotations-raycast? 0 Answers
raycast to determine pivot 1 Answer