Move UniversalCamera without a KeyCode

Hey there. I am using a UniversalCamera for some game. In combination with keysUp, keysLeft, … I attached KeyCodes to the UniversalCamera so it will move on keydown, which is working perfectly fine.

Now, let’s say I have some function that should trigger keysLeft, like myCamera.moveLeft(). I couldn’t find anything like it in the docs, is there actually something like this?

Here is a playground having a UniversalCamera where you could move with “W, A, S, D”. https://playground.babylonjs.com/#DWPQ9R#306

So, if I understand you correctly, you want to trigger the forward move without a keydown action. Move the camera forward not based on browser events.

This is not an “official” solution, as we don’t recommend using private members, but adding and removing from the keyboard input’s _keys array will get you when you want to go:

FreeCamera_MouseWheel | Babylon.js Playground (babylonjs.com)

Otherwise, you can look into the free camera keyboard input and replicate the code responsible for movement. You can also implement your own input system that will support that.

1 Like

Thanks a lot! Ya I already thought of implementing that on my own, just thought there would be another solution I was missing. But ya the private member would be my way to go actually. I am also no big fan of using private members, but this is a little better as I reuse the existing code from the UniversalCamera directly.