I’m making a game and in this game I need to rotate a planted using the mouse left button, so I used this code:
public int speed;
public int lerpSpeed;
private float rotationX;
private float rotationY;
private Quaternion fromRotation;
private Quaternion toRotation;
void Update () {
rotationX -= Input.GetAxis ("Mouse X") * speed;
rotationY -= Input.GetAxis ("Mouse Y") * speed;
toRotation = Quaternion.Euler (rotationY, rotationX, 0);
transform.rotation = Quaternion.Slerp (transform.rotation, toRotation, Time.deltaTime * lerpSpeed);
}
The Slerp works great, however if I hold the mouse left button and move it to the left, making the planet spin 180 degrees around itself and then hold again the mouse left button and move it up, the planet will spin downward instead of spin upward.
I need help on how to solve this, because I have already searched a lot and nothing seems to work.