[SOLVED] Clamp touch pad camera


I was experimenting the touch pad controls from the third person mobile controller. I ran into an error when trying to limit the camera on the y axis same as how you clamp it on mousemove with: this.eulers.y = pc.math.clamp(this.eulers.y, -90, 90);

However when I try that the camera keeps jittering to different positions like so:

How can I clamp a camera using the touch controller without the camera behaving like that?



Hi @nasjarta,

If you survey the values your this.eulers.y gets you will see that the effective range you are targeting is not between -90 to 90. Because on line 59 of your script you add 360 to your effect angle range.

Iā€™d say for your specific use case you can comment out that line and then your clamp will work at that point:

        if (this.eulers.x < 0) this.eulers.x += 360;
        //if (this.eulers.y < 0) this.eulers.y += 360;

        this.lastRTouchPoint.set(this.RTouch.x, this.RTouch.y);

        this.eulers.y = pc.math.clamp(this.eulers.y, -90, 90);
1 Like

Thanks @Leonidas :melting_face: