O'Reilly logo

Game Development with Three.js by Isaac Sukin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Exploring and Interacting

This chapter explains how users can interact with our games. We'll also cover some physics and use what we've learned to create a basic first-person shooter game.

Keyboard movement and mouse looking

In order to move our camera around, we're going to encapsulate some state, so let's define a KeyboardControls class in a new JavaScript file:

function KeyboardControls(object, options) { this.object = object; options = options || {}; this.domElement = options.domElement || document; this.moveSpeed = options.moveSpeed || 1; this.domElement.addEventListener('keydown', this.onKeyDown.bind(this), false); this.domElement.addEventListener('keyup', this.onKeyUp.bind(this), false); } KeyboardControls.prototype = { update: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required