WASD Keyboard Controls

Preface: I’m new to Babylonjs and Development in general, and may have missed/not understood some parts of the docs in relation to this topic, but I thought this might be a quick thing to add to it, to help fellow noobs like me :slight_smile:

Custom WASD + EQ Keyboard controls can be added scene’s camera like this:

        this.camera.attachControl(this.canvas, true);
        this.camera.keysUpward.push(69); //increase elevation
        this.camera.keysDownward.push(81); //decrease elevation
        this.camera.keysUp.push(87); //forwards 
        this.camera.keysDown.push(83); //backwards
        this.camera.keysLeft.push(65);
        this.camera.keysRight.push(68);

*The above was written for Typescript.
*Insert this inside of the createScene function.

The number inside .push() is a Keycode.
You can find the Keycode of any keyboard key stroke on this handy website: https://keycode.info/

7 Likes

I see you already started to write your book :slight_smile:
The only missing part in this tutorial is just a simple PG example.

1 Like

:joy:Yeah, in lieu of writing a book, I sneakily thought i may be able to help with tidbits instead, and my whacky project thread!

3 Likes