Rotation is applied incorrectly

Hello. I’m trying to make a smooth character rotation by interpolating between a fixed target value and the current rotation. The problem with turning back is setting the value of Vec3 (0,180.0), the character’s eulerAngle becomes Vec3 {x: 180, y: 7.016709369310694 e-15, z: 180}. And it is not possible to simply interpolate the y-axis, the rotation is not set above 90.

Hi @sergey_ch,

Yes, that’s to be expected, the Tween library will always rotate using the shortest route. Check the following threads, contain some workarounds:


I don’t use the tween library. Here is my code

    this.rotateAngle = {
        forward: new pc.Vec3(0,180,0),
        back: new pc.Vec3(0,0,0),
        left: new pc.Vec3(0,-90,0),
        right:new pc.Vec3(0,90,0)

Player.prototype.modelRotate = function(){
    const angl = this.model.getLocalEulerAngles().clone()
    const y = pc.math.lerp(angl.y, this.rotateAngle[this.currentDir].y, 0.5)
    angl.y = y

and it’s strange, you can see that the model tries to turn forward, but twitches and comes back.

Right, can you try using lerpAngle instead:

1 Like