- Home /
transform.rotation increment slows to a stop
I'm trying to have a plane continuously rotate as long as the left or right arrow key is down. It seems to work to a point then slows down to barely moving. Is there anything I'm missing? I'm just incrementing the transform.rotation.y value in the update function.
function Update () {
if (Input.GetKey("left")){
transform.rotation.y -=rotateValue * Time.deltaTime;
}
if (Input.GetKey("right")){
transform.rotation.y += Time.deltaTime * rotateValue;
}
}
Answer by johan-skold · Feb 28, 2011 at 12:15 AM
transform.rotation
is a quaternion. What you're doing when you're decrementing/incrementing the y-field is basically changing the axis to rotate around rather than actually rotating. What you're after is most likely transform.eulerAngles
or in the way I personally prefer:
transform.rotation *= Quaternion.AngleAxis(rotateValue * Time.deltaTime, Vector3.up);
Your answer
![](https://koobas.hobune.stream/wayback/20220613110553im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving an object in a circle towards joystick 0 Answers
How to make a cube rotate around player depending mouse position using New Input System 0 Answers
Get in turret by pressing a Key 0 Answers
Best way to prevent unnecessary input handling? 1 Answer
How to get smooth analog joystick rotation without "snapping"? 2 Answers