# UniversalCamera Lower Upper Beta Limit?

**URL:** <https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025>\
**Category:** Questions\
**Tags:** camera\
**Created:** [April 2, 2022, 9:55pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025 "2022-04-02T21:55:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![a\_bolog](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/a_bolog/32/6292_2.png) [@a\_bolog](https://forum.babylonjs.com/u/a_bolog)\
**Post date:** [April 2, 2022, 9:55pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/1 "2022-04-02T21:55:23Z")

</div>

How could I limit the UniversalCamera Lower Upper Beta Limit?  
Similar to ArcRotateCamera, but for first person camera.

[https://playground.babylonjs.com/#8Z0MKW#12](https://playground.babylonjs.com/#8Z0MKW#12)

 ![camera limit](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/6/9657255b5dd2d9c6bc95e804be075e24ffa0aeb6.png)

@PolygonalSun

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 4, 2022, 3:28pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/2 "2022-04-04T15:28:49Z")

</div>

You already cc @PolygonalSun , GG, @PolygonalSun you are becoming famous !!! 🙂

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [April 5, 2022, 4:00pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/3 "2022-04-05T16:00:25Z")

</div>

Hello @a_bolog , how are you doing?

I did a small playground sample with a possible solution for you. In the onViewMatrixChangedObservable I’m checking the view Matrix rotation component and forcing it to be within the constrains of the Upper and Lower bounds.

[Lower Higher Beta Limit | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#8Z0MKW#16)

Does that help you?

Let me know your thoughts on that!

---

<div class="post-metadata">

**Author:** ![a\_bolog](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/a_bolog/32/6292_2.png) [@a\_bolog](https://forum.babylonjs.com/u/a_bolog)\
**Post date:** [April 5, 2022, 4:19pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/4 "2022-04-05T16:19:28Z")

</div>

Hey man, that’s exactly the effect I’m looking for.  
But the camera gets stuck if I move it left right, does it happen on your end too?  
I can see that these camera values still change even if the camera is locked… hmm  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/1/514d33a6a71af8d6d927ef4f3f1ca0053f9ac52d.png)

I was playing around with the camera.rotation.x to somehow clamp it between +70 and -70 but can’t figure out how, maybe that’s an easier approach?

```auto
function clamp(number, min, max) {
  return Math.max(min, Math.min(number, max));
}

```

Many thanks

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [April 5, 2022, 5:36pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/5 "2022-04-05T17:36:01Z")

</div>

@a_bolog , I did an updated version that handles that fixes the camera lock issue. I think it is a little more complicated than it should be right now, but maybe it gets the job done?

[Lower Higher Beta Limit | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#8Z0MKW#19)

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [April 5, 2022, 6:51pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/6 "2022-04-05T18:51:06Z")

</div>

Using the view matrix to limit movement is a pretty awesome approach. Another approach I could recommend would be to remove the mouse input and just manually rotate things.

```auto
camera.inputs.removeMouse();
    scene.onPointerObservable.add((eventData) => {
        let angularSensibility = 2000;
        if (scene.getEngine().isPointerLock) {
            let evt = eventData.event;
            let offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
            camera.rotation.y += offsetX / angularSensibility;

            const offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
            let tentativeY = camera.rotation.x + offsetY / angularSensibility;
            if (Math.abs(tentativeY) < (MAX_ROTATION)) {
                camera.rotation.x += offsetY / angularSensibility;
            }
        }
    }, BABYLON.PointerEventTypes.POINTERMOVE);

```

---

<div class="post-metadata">

**Author:** ![a\_bolog](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/a_bolog/32/6292_2.png) [@a\_bolog](https://forum.babylonjs.com/u/a_bolog)\
**Post date:** [April 5, 2022, 7:01pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/7 "2022-04-05T19:01:14Z")

</div>

@PolygonalSun

Yes, it’s more predictable and enjoyable to use now.  
But I notice that it’s loosing the camera.inertia effect?

Many thanks for helping out guys.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [May 5, 2022, 6:44pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/8 "2022-05-05T18:44:49Z")

</div>

Hello @a_bolog just checking in, was your question answered?

---

<div class="post-metadata">

**Author:** ![a\_bolog](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/a_bolog/32/6292_2.png) [@a\_bolog](https://forum.babylonjs.com/u/a_bolog)\
**Post date:** [May 5, 2022, 10:18pm UTC](https://forum.babylonjs.com/t/universalcamera-lower-upper-beta-limit/29025/9 "2022-05-05T22:18:40Z")

</div>

@carolhmj  
Thanks for checking in, but not really, as it doesn’t work on the UniversalCamera without loosing inertia and touch controls on mobile.  
I was hoping maybe there is a more elegant way the same way it’s on ArcRotateCamera, beta limitXY
