Is there an option to rotate a UniversalCamera with left/right arrows?

The keyboard inputs on the UniversalCamera work fine, except I find the “strafe” movement of the left/right arrows to be suboptimal, since that means you essentially must move your hand to the mouse to re-orient the camera direction and explore. Strafing isn’t a natural movement, unless you’re a crab, so I’m hoping to tweak that by using the left-right arrows to re-target the camera (and direction of movement).

Is there an option buried somewhere, or an alternate keyboard input manager, that will use left/right to retarget the camera rather than moving laterally? Or, in a perfect world, one that would still allow strafing as well, but as a shift-arrow combo?

I found this forum topic, but this appears to involve directly handling low-level keyboard events. I suspect there’s a more idiomatic way of handling the keyboard in BabylonJS:

I also found this:

However, when pieced together, the sample code there is incomplete, and it seem to diverge quite a bit from the default keyboard input code here, leading me to think maybe this tutorial may be out of date with the current API.

https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts

If there’s no built-in support for this type of keyboard input, can I convert this topic into a feature request? :slight_smile:

Adding @PolygonalSun who is working on inputs :slight_smile:

1 Like

Hey @richardtallent,

As far as the documentation being out of date, I’ll take a look at it this week and see what’s going on.

For the current codebase, as far as I know, there is no “out of the box” way to enable keyboard rotation so I could see it being added as toggleable functionality (maybe a boolean camera param?). I could also see it being added as additional input like via WASD or something like that. In any case, I could look into it as well and figure out the best option.

That would be great, @PolygonalSun!

I looked at just trying to adapt the built-in one, but that will require me to actually learn and set up TypeScript, which I’ve successfully avoided so far (I do enough typing in C# :)), so I don’t know if I’d be able to issue a useful PR there.

A Boolean option would work, but if my use case sounds too specific to add another parameter to the camera constructors and addCamera(), I would be happy to just reconfigure keysLeft and keysRight after creating the camera, and set the arrow keycodes to some new freeCameraKeyboardMoveInput properties (keysCounterClockwise? keysLookLeft? keysRotateYMinus? Whatever names make sense…). I suppose that’s the more generalizable solution, since other actions could be added in the future (pitch, yaw, run, etc.).

The only limitation there is that I don’t currently see a way to configure Shift/Ctrl combination keys. (One hacky-but-easy solution there would be to mask some unused bits on the _keys buffer and keysX[] arrays to pass the state of those modifiers.)

PR is here Add rotate keys on uni camera by sebavan · Pull Request #10604 · BabylonJS/Babylon.js · GitHub

1 Like

Actually @PirateJC, I noticed we do not have any blurbs in the doc about input settings. Would probably be great to add ? so I can put the rotation feature in ?