Chapter 2. Building a demo that puts you in 3D space

 

This chapter covers

  • Understanding 3D coordinate space
  • Putting a player in a scene
  • Writing a script that moves objects
  • Implementing FPS controls

Chapter 1 concluded with the traditional “Hello World!” introduction to a new programming tool; now it’s time to dive into a nontrivial Unity project, a project with interactivity and graphics. You’ll put some objects into a scene and write code to enable a player to walk around that scene. Basically, it’ll be Doom without the monsters (something like what figure 2.1 depicts). The visual editor in Unity enables new users to start assembling a 3D prototype right away, without needing to write a lot of boilerplate code first (for things like initializing a 3D view or establishing a rendering loop).

Figure 2.1. Screenshot of the 3D demo (basically, Doom without the monsters)

It’s tempting to immediately start building the scene in Unity, especially with such a simple (in concept!) project. But it’s always a good idea to pause at the beginning and plan out what you’re going to do, and this is especially important right now because you’re new to the process.

2.1. Before you start...

2.2. Begin the project: place objects in the scene

2.3. Making things move: a script that applies transforms

2.4. Script component for looking around: MouseLook

2.5. Keyboard input component: first-person controls

2.6. Summary

sitemap