- Home /
Player spinning when upside down.
I'm making a game where the player moves around planets kind of like super Mario galaxy. When the player gets to the bottom of a planet he spins out of control.
The movement works fine on its own, but when I add mouse rotation it messes up.
private void FixedUpdate()
{
Vector2 lookDir = Input.mousePosition - transform.position;
transform.rotation = Quaternion.FromToRotation(Vector2.up, lookDir);
}
public void PlayerYRotate()
{
player.transform.rotation = Quaternion.Euler(new Vector3(player.transform.rotation.x, -transform.rotation.eulerAngles.z, player.transform.rotation.z));
}
I use this to get the angle to the mouse and set the player to match the orientation. Thanks!
Answer by QuitsDoubloon · Nov 19, 2020 at 10:19 PM
If anyone from the future finds this question, my weeks of pain and a 2000 character file of attempts have found a solution, its:
transform.rotation = Quaternion.FromToRotation(transform.up, (desired up vector3) ) * transform.rotation;
Its that simple.
Your answer
Follow this Question
Related Questions
Quaternion and rotation of object 1 Answer
Rotate GameObject To Look Down 1 Answer
can anyone find the issue with this code? 2 Answers
Rotation reversing for a single frame while turning. 0 Answers
Player model rotates forward with camera 0 Answers