- Home /
Question by
karafss · May 24, 2013 at 11:32 PM ·
rotationangleeuleranglesgetkey
rotate slowly!
i want rotate an object when i press a key once(getkeydown) for 30 degree.also i want to see rotation(slow rotation).how?
Comment
Answer by MikeNewall · May 24, 2013 at 11:54 PM
To change the speed you need to multiply the vector you want to rotate around by a speed variable. Check if the y rotation is greater than or equal to the target angle. If it's not carry on rotating, if it is then stop rotating.
public float speed = 10;
public float angle = 30;
private bool rotating = false;
void Update ()
{
if(Input.GetKeyDown(KeyCode.Space) && !rotating) rotating = true;
if(rotating && transform.eulerAngles.y <= angle)
{
transform.Rotate(Vector3.up * (speed * Time.deltaTime));
}
else if (rotating) rotating = false;
}