# How to properly rotate an already rotated object

Hello, people. I have a cube that is already rotated 45 degrees in X and Z (screenshot below).

I want this cube to rotate around the Y-axis, like I rotate it in Editor (gif below).

To do this, I wrote a simple script like this:

``````using UnityEngine;

public class CurrencyRotation : MonoBehaviour
{
[SerializeField] private bool _needToRotate;
[SerializeField] private float _rotationSpeed;

private Transform _localTransform;

void Start()
{
_localTransform = GetComponent<Transform>();
}

void Update()
{
if (_needToRotate)
{
_localTransform.Rotate(0, _rotationSpeed * Time.deltaTime, 0);
}
}
}
``````

But when using this script, the cube is rotated not only around the Y-axis, but also around the X and Z axes (gif below).

One of the solutions to this behavior is to create an empty object and place our cube in this empty object and then rotate not the cube itself, but this empty object (screenshot below). In this case everything works. But I would like to achieve this result without using empty objects.

How can I achieve this result without using an empty object?

Try replacing

``````_localTransform.Rotate(0, _rotationSpeed * Time.deltaTime, 0);
``````

with

``````_localTransform.Rotate(0, _rotationSpeed * Time.deltaTime, 0, Space.World);
``````

Hi!

`transform.Rotate` applies a rotation to the object relative to its current rotation, which might be tricky for your case.

What about updating the rotation using a simple Quaternion?

``````void Update()
{
if (_needToRotate)
{
var currentRotation = _localTransform.eulerAngles;

_localTransform.rotation = Quaternion.Euler(
currentRotation.x,
currentRotation.y + _rotationSpeed * Time.deltaTime,
currentRotation.z);
}
}
``````

In this example, we keep the rotation in the x and z axes, and update the rotation in the y axis based on `_rotationSpeed`. The direction of the rotation will depend on whether `_rotationSpeed` is positive or negative.