- Home /

# Rotating a model with increments

Hi there, I have an hexagon and I want to press a key and rotate it Smoothly by 60 degrees over the Z axis in order to have one of its faces aligned with the horizon, press the key again and rotate another 60 degrees, and so on by 60 degrees to the left/right.

I'm trying a few things but I can't get it to work properly I can make it work perhaps once or twice but it's kind of unstable, can anyone tell me please the best way to do this?

Here is the code I'm using but can't say if it is much of a help.

```
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
left = true;
}
if (left)
{
StartCoroutine(TurnLeft());
}
if (Input.GetKey(KeyCode.RightArrow))
{
right = true;
}
if (right)
{
StartCoroutine(TurnRight());
}
}
public IEnumerator TurnRight()
{
rotation = 60;
Quaternion to = Quaternion.Euler(0, 0, rotation);
transform.rotation = Quaternion.Lerp(transform.rotation, to, Time.deltaTime * 3f);
yield return new WaitForSeconds(2f);
transform.rotation = to;
right = false;
yield return null;
}
public IEnumerator TurnLeft()
{
Vector3 eulerAngles = transform.eulerAngles;
if (eulerAngles.z >= 0 && eulerAngles.z <= 60)
{
rotation = 60;
transform.eulerAngles = eulerAngles;
}
else if (eulerAngles.z >= 60 && eulerAngles.z <= 120)
{
rotation = 120;
transform.eulerAngles = eulerAngles;
}
Quaternion to = Quaternion.Euler(0, 0, rotation);
transform.rotation = Quaternion.Lerp(transform.rotation, to, Time.deltaTime * 3f);
yield return new WaitForSeconds(2f);
transform.rotation = to;
left = false;
yield return null;
}
private static float WrapAngle(float angle)
{
angle %= 360;
if (angle > 180)
return angle - 360;
return angle;
}
private static float UnwrapAngle(float angle)
{
if (angle >= 0)
return angle;
angle = -angle % 360;
return 360 - angle;
}
```

**Answer** by Nazirzadeh
·
Oct 18, 2018 at 04:01 AM

By pressing left/right arrow always your left/right variables become true. that means it is possible to call the StartCoroutine(TurnRight()); or StartCoroutine(TurnLeft()); many times before you actually set the variables to false.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.