# Getting the correct rotation problem

I have a slot machine with 3 reels. Each reel is a simple cylinder divided into 12 x 30 degree segments, with each segment having a picture. Match the pictures and you win.
When I pull the handle, I basically have a spin timer that rotates the reels until the time stops i.e

``````directionX = 1800;

function Update()
{
if(spin){
transform.Rotate (directionX * Time.deltaTime, 0, 0);
spinTimer -= Time.deltaTime;
currentAngle = transform.eulerAngles.x;
}
}
``````

The spinning and stopping all works nicely, I have code for that, but what stumps me here is, if I rotate the reel within Unity’s editor, i.e I set the rotation to 90 in the editor, I see a totally different picture on the reel than to the one if the reel had been rotated in game mode when the rotation of the cylinder returned by Unity is also 90. (Or any other rotation for that matter). The value of ‘currentAngle’ which I get from the reels x eulerAngle don’t match. In other words a different picture on the slot shows than what should according to the rotation of the wheel in the editor.

I’ve tried almost every way in the book I can to get the angle, using Quaternions and rotating the wheel using other methods, but I cannot for the life of me get the rotation of the wheel in the editor to match that of the value returned while the game is running.

I need this value so I can set the wheel’s rotation to snap to 30 degree intervals so if it lands close to the picture the rotation is snapped so the picture is displayed in the middle.

There is no rigidbody attached to the reel at all, it is simply the rotation of the mesh.

I don’t know what’s causing this discrepancy, but I would do it in a different manner: have a number rotating in module 12, multiply it by 30, convert to quaternion and set transform.rotation. It’s better than using Rotate freely and try to guess the position using eulerAngles (they can show very strange angles sometimes).

The script below uses this principle: angle rotates in modulo 12 and is used to set the transform rotation. When the reel slows down and stops, angle is rounded up and stored in number to indicate the number drawn (it’s 0 during the drawing):

```var rotSpeed: float = 18;  // speed in segments per second
var rollTime: float = 2.5;  // time to roll until stop
var number: int;  // number when reel stopped
private var angle: float = 0;
private var time: float = 0;

function Update(){
if (Input.GetKey("r")){
time = rollTime;  // keep rolling at full speed while r pressed
number = 0;  // number invalid while rolling
}
if (time > 0){
var t = time / rollTime;   // reduce speed during rollTime
angle = (angle + t * rotSpeed * Time.deltaTime) % 12;
transform.rotation = Quaternion.Euler(angle * 30, 0, 90);
if (t < 0.2){  // if speed below 20% rotSpeed...
if (angle % 1 < 0.05){  // roll until segment position error < 5%
number = Mathf.Ceil(angle);  // save number 1 to 12
time = 0;
}
} else {
time -= Time.deltaTime;
}
}
}
```

I’m guessing that in the Editor you are affecting the localRotation and this code affects the world rotation?