Mathf.LerpAngle - rotate a block via input

I am trying to get a block to smooth rotate from one angle to another

All I seem to get at the moment it the block jumping into positions and not the smooth rotate I was hoping for ?

here is my code so far…

var current_angle = 0; 
var desired_angle = 0;

function Update () {

 if (Input.GetKey ("up")) {
        desired_angle = 0;
    }
    else if (Input.GetKey ("right")) {
        desired_angle = 90;
    }
    else if (Input.GetKey ("down")) {
        desired_angle = 180;
    }
     else if (Input.GetKey ("left")) {
        desired_angle = 270;
     }
  
var angle = Mathf.LerpAngle(current_angle, desired_angle, Time.time);
transform.eulerAngles = Vector3(0, angle, 0);


}

Try using Time.deltaTime instead of Time.time?

EDIT: Also, it looks like current_angle is always zero, which means you will always be lerping from 0. I doubt this is what you want? Maybe try this:

var current_angle = 0; 
var desired_angle = 0; 

function Update () { 

 if (Input.GetKey ("up")) { 
        desired_angle = 0; 
    } 
    else if (Input.GetKey ("right")) { 
        desired_angle = 90; 
    } 
    else if (Input.GetKey ("down")) { 
        desired_angle = 180; 
    } 
     else if (Input.GetKey ("left")) { 
        desired_angle = 270; 
     } 
  
current_angle = Mathf.LerpAngle(current_angle, desired_angle, Time.deltaTime); 
transform.eulerAngles = Vector3(0, current_angle, 0); 


}

nice - it now rotates but only when i press down and seems to only get to about 88 degrees before it stops , pressing up gets me back to 0 degrees and so does pressing left at that point … thanks

Duh. That’s what I get for not looking at the docs.

I tested this one and it works for me:

var desired_angle = 0;
var speed = 1.0;

function Update () { 

 if (Input.GetKey ("up")) { 
        desired_angle = 0;
    } 
    else if (Input.GetKey ("right")) { 
        desired_angle = 90; 
    } 
    else if (Input.GetKey ("down")) { 
        desired_angle = 180; 
    } 
     else if (Input.GetKey ("left")) { 
        desired_angle = 270; 
     } 
     
 var target_rotation = transform.rotation.Euler(0, desired_angle, 0);
 transform.rotation = Quaternion.Slerp( transform.rotation, target_rotation, Time.deltaTime * speed );
}

Sorry about that!

Thank you - someone mentioned slerp at some point, I was getting very confused - if I ever manage to put anything more polished together I will post it.

adam