- Home /
Rotation according to gravity in a 3 dimensional space
A while ago someone posted a question asking how to rotate an object along it's local z axis so that it's local y vector aligns with a specified gravity vector.
My question is how to apply this logic, but in a more complex way; how to rotate an object along both it's local x AND it's local z axis in order to align it's y axis with a specified gravity vector.
In simpler terms, I'm trying to rotate a player to align with the gravity vector in the least amount of rotation possible. My reason for doing this is that the game is a first person game that is played in zero g, unless the player enters a "gravity box", in which case they will align with the gravity box's gravity vector. The reason for the "least amount of rotation" rule is to make the change in gravity smooth and happen with little confusion. I've tried several other solutions (such as simply setting transform.up to equal opposite the gravity vector) that, while do align the y axis with the gravity vector, set the forward vector of the object to be a global forward, which is bad.
TL;DR: I want to rotate an object so that it's up vector aligns with a specified gravity vector in the least amount of rotation possible. I don't care what the forward or right vector is at the end of the rotation as long as the up vector is aligned.
Your answer
![](https://koobas.hobune.stream/wayback/20220612184749im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating a character's velocity? 3 Answers
Game Object rotation sometimes doesn't match defined quaternion 0 Answers
make projectiles always hit target 1 Answer
Why does my Physics.gravity revert value change when accessed by one script, but not another? 0 Answers
Rotate Towards doesnt work as expected 2 Answers