Hello everyone!
I have an object which I rotate by mouse movement. The object’s rotation (axis x) increases when mouse moves up and decreases when the mouse moves down (I use Input.GetAxis (“Mouse Y”)). The problem I have is how to stop the rotation when it reaches a certain point, for example 200 degrees.
if (rotation.x < 200) {
object.transform.Rotate (mouseY, 0, 0);
}
else if (rotation.x >= 200) {
if (mouseY < 0) {
object.transform.Rotate (mouseY, 0, 0);
}
}
With this code the value increases and decreases normally when it’s below 200, but when it comes above it can only be decreased. The problem is, when I move mouse fast enough the value stops at, for example, 205, instead of 200.
My question is, how to make the rotating stop exactly at number 200?
I’ve already tried many ways, such as slowing down the mouse movement, making the object rotate back or forcing the rotation to be exactly 200 when the value is over 200, etc. but these are only workarounds, which do not work perfectly and create a lot of bugs.
I want it to look like that:
rotation.x = 190
(mouse move up)
rotation.x = 200
(mouse move up)
rotation.x = 200
(mouse move down)
rotation.x = 190
Feel free to ask for details, I really appreciate any help!