Given two variables, a Vector3 representing body velocity and a Quaternion representing body's local rotation, how could I normalize the velocity vector so that it's always oriented towards the default Vector3.forward direction?
The context of this problem is that I have a 2D blendtree for character movement animations. I wanted to use the RigidBody.velocity
to control the two blendtree axes. This did not work as I initially expected because, depending on body rotation, the velocity also rotates to that direction and this when I'm moving forwards but my body is rotated 90 degrees to the right, my right (x) velocity would be 10 and my forward (z) velocity would be 0. In that case I would like to, using the current body rotation and velocity values, "normalize" the given velocity vector so that it has 10 in forward (z) velocity and 0 in right (x) velocity any time the entity is moving forward, no matter it's orientation.
I've tried playing with Vector3.RotateTowards
and Quaternion.LookRotation
but I haven't gotten the desired results and I don't really know what to look for.