[SOLVED] How could I clamp rotation on swerving up down (touch inputs)?

I want to clamp rotation along the x-axis.

let swipeDelta = 0;

if (this.touching) // moving touch on device
    {
        swipeDelta = this.currentPosition.y - this.startPosition.y;

        this.currentRotation.copy(this.entity.getLocalEulerAngles());

        // clamp x rotation
        //this.currentRotation.x = pc.math.clamp(this.currentRotation.x, -45, 0)

        this.entity.rotateLocal(-swipeDelta * this.speed, 0, 0);
    }

Hi @yash_mehrotra,

Use setLocalEulerAngles instead of using rotateLocal, that way you can clamp the final angle before applying it.

let angle = this.currentRotation.x - swipeDelta * this.speed;
angle = pc.math.clamp(angle, -45, 0)

this.entity.setLocalEulerAngles(angle, 0, 0);

thankyou, it worked.