# Universal Camera jumping around and not handling control very well

**URL:** <https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483>\
**Category:** Questions\
**Created:** [August 22, 2023, 6:09pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483 "2023-08-22T18:09:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 6:09pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/1 "2023-08-22T18:09:18Z")

</div>

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#ZDAFVT%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I’m trying to lock control of the camera and move around a map. I’ve been noticing some glitches in my personal project. From what I see, when I try to spin smoothly in a circle it’ll occasionally spin incredibly fast for a split second. As a test, I captured the cursor and then tried to look at each of the spheres in a circle at a steady pace. It seemed to change speeds randomly, even more than what I would expect from mouse acceleration (which I would hope is off)

In attempting to repro it in the playground, what I built there is much worse. It’s always much faster than I want and you can’t get your cursor back easily. I’m running this in Firefox.

I’m using two monitors, if that helps.

---

<div class="post-metadata">

**Author:** ![DavidL](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidl/32/34549_2.png) [@DavidL](https://forum.babylonjs.com/u/DavidL)\
**Post date:** [August 22, 2023, 9:18pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/2 "2023-08-22T21:18:12Z")

</div>

Commenting out: camera.inertia = 0.5  
made things much smoother for me. It can’t be that easy though, is it?

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 9:35pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/3 "2023-08-22T21:35:24Z")

</div>

I think that this helps (not necesarrily commenting it out, but setting the inertia to 0) but it isn’t fixing my problem.

Here’s another way to demonstrate. Capture the mouse and aim at a target. Place your other finger on the desk touching the side of your mouse, then move your mouse away then back to your finger. You would expect the camera to rotate away, then right back to the original target. In reality, the camera goes all over the place. A swipe will not act the same way every time.

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 9:39pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/4 "2023-08-22T21:39:37Z")

</div>

Here’s something else I noticed, which is probably a Bug with the Playground

Go into the playground and remove lines 67-70. Restart the app. See that the pointer is still captured, even though the code to capture the cursor is gone.

I suspect if the event listener is not being properly cleared there might be unintended consequences.

---

<div class="post-metadata">

**Author:** ![DavidL](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidl/32/34549_2.png) [@DavidL](https://forum.babylonjs.com/u/DavidL)\
**Post date:** [August 22, 2023, 9:44pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/5 "2023-08-22T21:44:58Z")

</div>

Sometimes you have to close the browser and restart, I’ve noticed lingering bugs as well even though I fixed the code, a clean start is required sometimes

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 9:53pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/6 "2023-08-22T21:53:10Z")

</div>

[![]( " - YouTube") ](https://www.youtube.com/watch?v=6H2O9ghXEqc)

Here’s a video of me attempting to slowly, smoothly point the cursor back and forth between two points in the world. There’s some obvious stutter and some wild jumps. This was using a fresh Chrome browser.

---

<div class="post-metadata">

**Author:** ![DavidL](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidl/32/34549_2.png) [@DavidL](https://forum.babylonjs.com/u/DavidL)\
**Post date:** [August 22, 2023, 9:55pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/7 "2023-08-22T21:55:00Z")

</div>

Video marked as private, unable to view.

Sometimes the simplest solutions are the best, have you tried arcRotateCamera?

Hope that helps, works good on my end!

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#ZDAFVT%233)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 9:55pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/8 "2023-08-22T21:55:29Z")

</div>

Oops, meant to be Unlisted. Fixed

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 22, 2023, 9:58pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/9 "2023-08-22T21:58:09Z")

</div>

> [@DavidL](#):
>
> have you tried arcRotateCamera?

I don’t think arcRotateCamera will work well for a first-person puzzle game.

---

<div class="post-metadata">

**Author:** ![DavidL](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/davidl/32/34549_2.png) [@DavidL](https://forum.babylonjs.com/u/DavidL)\
**Post date:** [August 22, 2023, 10:22pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/12 "2023-08-22T22:22:34Z")

</div>

Could it be the way you are requesting pointer lock? Maybe try it like this

> [@Locking camera to mouse (like in an FPS)](https://forum.babylonjs.com/t/locking-camera-to-mouse-like-in-an-fps/42370):
>
> I’m looking to build a first-person experience, and one of the first things I noticed was the UniversalCamera (“the one to choose for first person shooter type games”) does not, in fact, track the mouse as one would expect (i.e. like Minecraft). The closest thing I found was this: In that playground, the camera turns to face wherever you move towards, but still requires you to click and drag to turn the camera. I’m looking for functionality that locks my cursor to the center of the screen, suc…

I may not be helpful but at least your question gets a bump every time I reply haha

That async/await is what I’m looking at as the possible culprit…

---

<div class="post-metadata">

**Author:** ![BoldBigflank](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/boldbigflank/32/4426_2.png) [@BoldBigflank](https://forum.babylonjs.com/u/BoldBigflank)\
**Post date:** [August 23, 2023, 2:53pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/13 "2023-08-23T14:53:11Z")

</div>

Alright, here’s a partial fix.

In [this article](https://web.dev/disable-mouse-acceleration/) it shows how mouse acceleration messes up captured pointer data, and how to fix it. Unfortunately, the `unadjustedMovement` option is only partially [compatible](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestPointerLock#browser_compatibility) with modern browsers. Even so, I needed to use `// @ts-ignore` to stop an error from being called when calling `requestPointerLock` with an options object.

With all that, on Chrome my mouse movement is smooth with no jumps. Firefox still captures the cursor but doesn’t disable mouse acceleration.

---

<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:** [August 23, 2023, 7:28pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/14 "2023-08-23T19:28:03Z")

</div>

Assigned @PolygonalSun on August 23, 2023, 7:28pm UTC



---

<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:** [August 30, 2023, 7:37pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/15 "2023-08-30T19:37:31Z")

</div>

Hey, with respect to lines 67-70, when you hit the Run button on the playground, it’s going to keep adding event listeners for `click` without clearing out the previous ones. This is because rerunning a script in the playground will only reset the status of the engine but not affect anything outside of that context unless explicit coded (ie. putting in code to clear out all `click` event listeners on the canvas). I’d recommend either using the canvas’ `onclick` callback or something like:

```auto
scene.onPointerObservable.add(async (evt) => {
    canvas.requestPointerLock();
}, BABYLON.PointerEventTypes.POINTERTAP);

```

You could also use the engine’s `enterPointerlock()` function to do the same thing. As far as the jumpy behavior, is there a reason why you chose 500 for `angularSensibility` (sensitivity?

---

<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:** [August 30, 2023, 7:37pm UTC](https://forum.babylonjs.com/t/universal-camera-jumping-around-and-not-handling-control-very-well/43483/16 "2023-08-30T19:37:45Z")

</div>

Unassigned @PolygonalSun on August 30, 2023, 7:37pm UTC


