- Home /
transform.forward doesn't correspond to rotation
I have a script that uses a raycast with the direction of transform.forward of a camera. The only problem is that transform.forward doesn't rotate with the camera, it's global and works like Vector3.forward. Why is that happening?
Please, edit your question, provide your code, and add screenshots with a Debug.DrawRay
. There is no reason the problem you describe would happen.
I was using GameObject.FindWithTag("Player").transform.forward and the DrawRay drew the ray facing the global forward and not corresponding to the rotation. I guess Unity just doesn't want to get transform.forward of other separate transforms.
Unity works perfectly fine for this kind of basic computation, you surely did something wrong, but since you did not provide any script, nobody will know why it didn't work.
Answer by GreatCorn · Aug 07, 2018 at 01:32 PM
I was using a script that would find the object and then get its transform.forward, so that is why it didn't work. I made an another script that I assigned to that gameObject that would get the transform.forward and return it with a variable that I accessed through the first script. Weird.
Your answer
Follow this Question
Related Questions
How to detect VR camera movement? 0 Answers
Raycasting with Rotation of Camera 0 Answers
How to detect if player is facing towards enemy's back 2 Answers
"Fake" Vector3.forward? 3 Answers
Measuring XYZ coordinates in Unity vs in real life. 1 Answer