Turn a vector3 relative to a look direction
Hi guys :D I'm drawing a blank here, and i can't even figure out how to go about searching for it on google. This should be so simple, yet i just can't figure it out.
I have a vector3 i call speed (y is always 0), and a first person camera. Im trying to turn this speed vector in the direction of the camera so that speed.z is always forward and speed.x is always the sides of the camera.
I hope someone can point me in the right direction :)
Comment
Best Answer
Answer by Hellium · Oct 28, 2017 at 01:57 PM
Use Quaternion.LookRotation
:
Vector3 newSpeed = Quaternion.LookRotation(cameraTransform.forward, cameraTransform.up) * speed;
https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html