Pointer Lock Problem

I’m here again with another question, but this one is rather based on my inexperience with JavaScript. I have a problem with pointer lock, how do I get the change in mouse position even with pointer lock on, I know it’s possible because Babylon’s ArcRotateCamera does it but i don’t know how.

this is the playground I’m working in:

https://www.babylonjs-playground.com/#G703DZ#26

I’m using scene.onPointerMove on line 131 and the pointer lock on line 236.

I have used log in the onPointerMove function and observed that it prints even with the pointer lock on, but it prints the same coordinates as where the mouse was before the lock.

Hi TheNosiriN,

I think you need to use different mechanisms to read the mouse depending on whether the pointer is locked or not. If you look at flyCameraMouseInput.ts, it contains two completely separate methods for tracking mouse movement, one for when the pointer is locked and one for when it isn’t. It sounds like what you want to do is pretty similar, so hopefully the implementation in that file will be of help. Best of luck!

Thanks for replying, I already got this working some days ago using mozilla’s docs on pointer lock: https://www.babylonjs-playground.com/#G703DZ#87 at line 503

1 Like