Controls

The two controls we use in this book are the fly controls and orbit controls.

Fly Controls

We used FlyControls.js to fly around space in both Chapter 5, ​Functions: Use and Use Again​ and Chapter 13, ​Project: Phases of the Moon​. We can create fly controls after the camera is defined with this:

​ ​var​ controls = ​new​ THREE.FlyControls(camera);

Then the following keys let you fly through the scene:

Motion

Direction

Keys

Move

Forward / Backward

W / S

Move

Left / Right

A / D

Move

Up / Down

R / F

Spin

Clockwise / Counterclockwise

Q / E

Spin

Left / Right

Left Arrow / Right Arrow

Spin

Up / Down

Up Arrow / Down Arrow

The following options are available for fly controls:

​ controls.movementSpeed = 100;
​ controls.rollSpeed = 0.5;
​ controls.dragToLook ...

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.