I’m working on a small maze game to learn BabylonJS (GitHub - Corysia/squeakers: A simple maze game. Can you find the cheese?) and I’d like to disable the ability to rotate the camera on mouse left-click. I’ve the functionality I want with a right-mouse click and intend to use left-mouse for selection. Is there an easy way to disable that in the FreeCamera, or do I need to wipe all inputs and add back in the ones I want?
Hello, you can try this :
camera.inputs.attached.pointers.buttons = [ 2];
And maybe have a look there : Deactive some Camera inputs
That does seem to work great in the playground, but not in my app. I’m getting undefined
for pointers.
constructor(location = new Vector3(0, 0, 0), scene = SceneManager.Instance.Scene, canvas = SceneManager.Instance.Canvas, ) {
console.debug("FirstPersonController");
this.scene = scene;
this.camera = new FreeCamera("FirstPersonController", location, scene);
let manager = this.camera.inputs.attached;
console.log("Manager: ", manager);
console.log("pointers: ", manager.pointers);
// this.camera.inputs.attached.pointers.buttons = [2];
Looking at the console, I only see keyboard
and mouse
as attached inputs.
If I enable this.camera.inputs.attached.pointers.buttons = [2];
, then I get the following error:
ERROR in /Users/corysia/Dev/BabylonJS/squeakers/src/FirstPersonController.ts
./src/FirstPersonController.ts 20:45-52
[tsl] ERROR in /Users/corysia/Dev/BabylonJS/squeakers/src/FirstPersonController.ts(20,46)
TS2339: Property 'buttons' does not exist on type 'ICameraInput<FreeCamera>'.
ts-loader-default_e3b0c44298fc1c14
@ ./src/main.ts 16:0-64 46:46-67
I thought perhaps it was because I was using a FreeCamera, but I run in to the same problems with an ArcRotateCamera.
Experimenting in the Playground, I see the same problem if I convert to TypeScript, which is what I’m using.
With the hints @samuelgirardin provided, I was able to find a TypeScript solution. While there’s a mouse
apparently available down in there somewhere, it’s not as accessible in TypeScript. So, adding it in, then disabling in a similar way works great.
This similar thread might offer some more insight
It did, thanks. It helped me understand how to handle an ArcRotateCamera, too. Because the API is different.