- Home /
How would I go about finding the rotation corrresponding to the force added to the y and z axis of a object?
Heyo! I am working on a puzzle game project and in this game I have jump pads that pull you off the ground, what I need to figure out is the rotation at which the character(player) is being shot off the ground, what I have is pretty basic right now as far as getting off the ground goes, it is just adding force to the rigidbody on Y by the variable forcePower and on Z by how fast the character is going. I need to find the rotation that would put his local y axis in the same direction as he is being forced.
Thanks for the help in advance!
Answer by robertbu · Oct 29, 2013 at 03:56 PM
After you've added the force, this will align the local 'Y' with the velocity:
var q = Quaternion.FromToRotation(transform.up, rigidbody.velocity);
transform.rotation = q * transform.rotation;
This will likely also work:
transform.up = rigidbody.velocity;
These code fragments align with the direction he is going. Your question says 'being forced'. If you are trying to align with the direction of the force (not necessarily the direction he is going), then replace rigidbody.velocity with the vector you are using in AddForce().
Your answer
Follow this Question
Related Questions
Movement Relative to both Camera and XZ Plane 3 Answers
How do I align my player transform to waypoints and without restricting Z Axis rotation? 2 Answers
Convert local forward into world vector 1 Answer
How do you make a gameobject rotate slowly to the direction of the mouseclick 0 Answers
LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers