# stopping a rotation

Hey guys so I having my character rotate 180 degrees however he doesn’t stop at 180. it would just continue to spin as long as i hold the button. Even if i press it it would only spin a bit, not the full 180. i’m also trying not to make it spin to the 180 degree just turn around no matter the position he’s in. Here’s my code I use to make him spin.

``````if (Input.GetKey(KeyCode.S))
{
targetAngles = transform.eulerAngles + 180f * Vector3.up; // what the new angles should be

transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAngles, smooth * Time.deltaTime); // lerp to new angles

}
else
{

}
``````

Your problem lies on line 3. Your target angle is not the current rotation of the object + 180 degrees, it is the the rotation of the object when you first pressed the S key + 180 degrees. So I would do something like this

``````if (Input.GetKeyDown(KeyCode.S)){
targetAngles = transform.eulerAngles + 180f * Vector3.up;
}

if (Input.GetKey(KeyCode.S)){
transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAngles, smooth * Time.deltaTime);
}
``````

However, this would make it so that the character only turns towards your new target as long as you hold the key down. If I’m interpreting your “i’m also trying not to make it spin to the 180 degree just turn around no matter the position he’s in” comment correctly, you might be wanting to do something like this:

``````if (Input.GetKeyDown(KeyCode.S)){
transform.Rotate(Vector3.up, 180f);
}
``````

This instantaneously rotates your character 180 degrees around the Y axis.