- Home /
Rotate problem.
there is a cube and the y rotation of the cube is random. How can i round the rotation to 90 or 180 or 270 or 0(to the nearest number)?
Answer by KellyThomas · Dec 22, 2013 at 10:13 AM
deg = 90 * (int)(deg / 90)
i want to face the object to the player but with 90 180 270 or 0 degrees
Do you have the ideal (unrounded) rotation to face the player?
Strange...
When I drop this script on an object in my scene:
#pragma strict
var idealRotation: Vector3;
function Update () {
var euler: Vector3 = idealRotation;
euler.x = 90 * $$anonymous$$athf.RoundToInt(euler.x / 90);
transform.rotation = Quaternion.Euler(euler);
}
And then use the inspector to play with the x component of idealRotation
, I find that:
x < 45 rounds to 0
45 < x < 135 rounds to 90
135 < x < 225 rounds to 180
225 < x < 315 rounds to 270
315 < x rounds to 360 (and is treated a zero).
what you wrote that is works i think i missed something thanks :D
Your answer
Follow this Question
Related Questions
Rotate Towards doesnt work as expected 2 Answers
Round to nearest .5? 2 Answers
Round to 0.5, 1.5, 2.5 ... 1 Answer
Mathf doesn't work properly... 1 Answer
Getting an object to rotate back to zero after key is released 2 Answers