Bounding the rotation of an entity

I’m hoping someone can point me in the right direction here. I’m currently using the following code for the rotation of an entity with a mouse in my app:

Pulse1.prototype.onMouseMove = function (event) {
if (this.factor > 0) {
var mouse = this.app.mouse;
if (mouse.isPressed(pc.MOUSEBUTTON_LEFT)) {
this.rotate(event.dx2, event.dy2);
}

This works great and I’m able to rotate the entity freely.

What I am trying to do now is set rotation limits for both the x & y axes (i.e., -30 degrees to +30 degrees). If someone could offer a example of code for this or point me to a good reference, the help would be greatly appreciated. Thanks!

The easiest thing to do here is to use your own variables to store and set the pitch (x) and the yaw (y) rotation and set the entity’s eular angles every frame using your variables. This way, you can limit the rotation quite easily.

I’m not 100% sure what type of rotation behaviour you want so here’s 2 variants:
https://playcanvas.com/project/597018/overview/limit-rotation
https://playcanvas.com/project/586330/overview/the-room-item-exam

Thank you for your help, yaustar. I’ll review these examples.