- Home /
Quaternion snaps to a rotation when moving (and with input)?
Hi, I am trying to make a simple script where if you press the horizontal keys, a cube rotates ten degrees on the z axis, and if you press the vertical keys, it rotates ten degrees on the x axis. I have figured a script for it, and it works well but I have a problem. Normally, if I were to press a, the cube would smoothly rotate from 0 to 10 degrees, but if I were at 10 degrees already it would snap to 0 degrees and then move smoothly to -10. I can't seem to find a solution the problem, here is my code:
void FixedUpdate () {
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(vertical * maxangle, 0.0f, -(horizontal * maxangle));
rb.transform.rotation = Quaternion.Euler(movement);
}
By the way, maxangle = 10. I am a beginner so I cannot find an answer. Any help would be appreciated! Thank you!
Yeah, that's the behavior you've written here. Consider your line:
Vector3 movement = new Vector3(vertical * maxangle, 0.0f, -(horizontal * maxangle));
Is that line accounting for the ball's current rotation?
Answer by ArseneySorokin · Sep 27, 2018 at 11:27 AM
Change
rb.transform.rotation = Quaternion.Euler(movement);
To
rb.transform.Rotate(movement);
You always set the rotation to "movement" which is always the same value. Instead, you should be adding "movement" to your current rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220612175233im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotation with a slider 2 Answers
Choppy rotation of character around y-axis 1 Answer
smooth look at with offset 0 Answers
Smooth reset rotation problem 1 Answer
Rotation - Simple Question 0 Answers