First, a quick overview of my problem: I have a game entity which has a quaternion to represent its rotation/orientation. It also has a 3D vector in world space for its linear velocity. From the perspective of the entity there are also 3 virtual axes (the standard z=forward/backword, y=up/down, x=left/right).

With those relevant pieces, I want to find the amount of velocity relative to one of the entity's virtual axes (i.e. how fast is it moving to its right) so that I can display that to the player and/or apply a counteracting force in that direction.

I have a vague idea that I need to transform the unit vector corresponding to the direction I'm querying by the orientation quaternion and then calculate the angle between the result and the velocity vector. Then with that angle figure out how much of the velocity magnitude is in the target direction (maybe using cosine?).


Turn the quaternion into a 3x3 matrix, transpose it (shortcut for the inverse of a purely rotational matrix), apply this matrix to your world space vector and you now have your model space velocity vector (entity's virtual axes: X=right, Y=Up, Z=forward or backward).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.