# Rotation: x+z = z error

I want to create a rolling figure and it works fine with X rotation always, but with Z rotation I’ve got strange things. It looks like after X-rot Z axis is moved and sometimes my figure spins like YRotation. How to avoid that ?

``````private Vector3 Rotation = Vector3.zero;

void Start ()
{
Model    = GameObject.Find("Model");
Rotation = Model.transform.eulerAngles;
}

void Update ()
{
MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
MoveDirection = transform.TransformDirection(MoveDirection);

// Coordinates flip
Rotation.z -= MoveDirection.x;
Rotation.x += MoveDirection.z;

Model.transform.eulerAngles = Rotation;
``````

}

Your problem is line 12. I have to guess a bit on what you are trying to do with local vs world axes of rotation, but for the typical use you don’t need to do a TransformDirection() on the MoveDirection. Even if you are trying to rotate on a world axis, TransformDirection() would not be the way to handle the rotation. For rotating about the local object axis:

``````Rotation.z -= Input.GetAxis("Horizontal");
Rotation.x += Input.GetAxis("Vertical");
Model.transform.eulerAngles = Rotation;
``````

Since everything is relative, you could simplify it further:

``````Model.transform.Rotate(Input.GetAxis("Vertical"), 0.0, -Input.GetAxis("Horizontal"));
``````

I don’t know what your LocalRotation variable is, but if it is the objects local rotation, then the x rotation will change the position of the x axis. to keep the rotation global, or relative to world space i would use.

``````thegameobject.transform.rotation.eulerAngles.x += MoveDirection.x;
``````

They explain it really well on a similar question here.