# Rotation on only single axel while others staying still

Currently rotation is going like this:

I would it need to rotate only on X-axel while Y would stay 0 and Z would stay 90.
I have tried transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime) and transform.Rotate(0f, spinSpeed * Time.deltaTime, 0f), but both have same problem. Currently code isn’t completed and at end it would find closes rotation from list and use it as targetRotation.

``````using UnityEngine;
using System.Collections;

public class Slot : MonoBehaviour {
public Vector3 eulerAngleVelocity;
public float spinSpeed;
float spinSpeedOrig;
public float timer;
public float currentRotation;
public float targetRotation;
public float goingRotation;
public float timerTime;
bool once;

void Start()
{
spinSpeedOrig = spinSpeed;
timer = Random.Range (30.5f, 50f);
}

void Update()
{
if(timer > 0)
timer -= Time.deltaTime;
else if(spinSpeed > 0)
spinSpeed -= Time.deltaTime * 100;
else if(!once)
{
once = true;
spinSpeed = 0;
currentRotation = transform.eulerAngles.x;
print(currentRotation);
}
else
{
timerTime += Time.deltaTime * 0.1f;
goingRotation = Mathf.Lerp(currentRotation, targetRotation, timerTime);
transform.eulerAngles = new Vector3(goingRotation, 0, 90);
}

eulerAngleVelocity = new Vector3(0, spinSpeed, 0);

}

void FixedUpdate()
{
//transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime);

//transform.Rotate(0f, spinSpeed * Time.deltaTime, 0f);

Quaternion deltaRotation = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime);
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
}
}
``````

The problem you outline is not fixable…directly. Unity uses Quaternions for rotations. Euler angles are derived from the Quaternion. For example, if you do:

`````` transform.eulerAngles = new Vector3(180.0f, 0.0f, 0.0f);
Debug.Log(transform.eulerAngles);
``````

The output is (0,180,180), which is the same physical rotation, but a different euler representation.

There a couple different ways to work around the issue. Assuming there is nothing else impacting the rotation of this object, I recommend treating eulerAngles as write-only. This means you will need to get rid of line 31, and instead get the rotation from an initialized value in Start. It also means if you do any kind of reset on this rotation, you will need to assign ‘currentRotation’ from either ‘goingRotation’ or ‘targetRotation’ depending on how and why you do the reset.