# Rotation question using quaternions

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I currently have a planet in my game which I plan to have a character walking on. I need to rotate this character so that his feet are always touching the ground. I have a feeling I'll need to use quaternions for this, but I'm not sure what to do mathematically. Here's what I know: 1) I know the center of the planet (0,0,0) 2) I know the location of the character on the surface in Cartesian coordinates. 3) I know the "up" vector (surface vector) at the current player's location by subtracting #1 and #2. 4) The default "up" vector for a player in world space is (0,1,0) (spine is aligned with the Y axis) I also have a quaternion object I can use. Help is appreciated.

##### Share on other sites
The only other thing you need is a forward vector. With an up vector and a forward vector, you can take their cross product as a right vector and build a rotation matrix. The columns (or rows, depending on the convention you're using) of a rotation matrix are just a forward, up, and right vector.

##### Share on other sites
What should the default quaternion for my model be? Should it be a 0 degree angle around the 0,1,0 axis? And then concatenate the world rotation quaternion to that one?

##### Share on other sites
First, the usual admonition: you don't need to use quaternions to accomplish this (although you can certainly use them if you wish).
Quote:
 Original post by MrDoomMasterWhat should the default quaternion for my model be? Should it be a 0 degree angle around the 0,1,0 axis? And then concatenate the world rotation quaternion to that one?
The 'default' would simply be the identity quaternion (x = y = z = 0, w = 1).

However, you'll probably want to update the orientation incrementally rather than try to build it from scratch each frame. To do this, compute the rotation that will rotate the character's up vector onto the surface normal, and then apply it to the character's orientation (don't forget to normalize occassionally).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634124
• Total Posts
3015661
×