# How to use lerpAngle?

How to use lerpAngle? Looks like I’m doing sth wrong I want to lerp angle from 0 to 180 degrees on press key left or right

`````` update(dt) {
const left = pc.app.keyboard.wasPressed(pc.KEY_LEFT);
const right = pc.app.keyboard.wasPressed(pc.KEY_RIGHT);

this.rotate(left, right);
}
rotate(left, right) {
const height = 1;
const distance = 4;

const lookAtPointPos = this.lookAtPoint.getPosition();

orbitAngle = pc.math.lerpAngle(orbitAngle, 180, 0.5);

this.entity.setLocalPosition(lookAtPointPos);
this.entity.setEulerAngles(0, orbitAngle, 0);
this.entity.translateLocal(0, height, distance);
this.entity.lookAt(lookAtPointPos);

if(left){
orbitAngle -= 180;
}
if(right){
orbitAngle += 180;
}

}
``````

Hi @grzesiekmq,

`pc.math.lerpAngle` will lerp between 0-360 and the arguments that you pass are:

• from
• to
• alpha

So a way to smoothly go from 0 to 180 is (example code):

``````MyScript.prototype.initialize = function(){
this.currentAngle = 0;
this.targetAngle = 0;
this.animSpeed = 5;
};

MyScript.prototype.update= function(dt){
this.currentAngle = pc.math.lerpAngle(this.currentAngle, this.targetAngle, this.animSpeed * dt);
};
``````
2 Likes