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 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 the depiction in figure 2.1). 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)
CH02_F01_Hocking3

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.

NOTE

Remember, the project for every chapter can be downloaded from the book’s website (http://mng.bz/VBY5). First open the project in Unity and then open the main scene (usually just named Scene) to run and inspect. While you’re learning, I recommend you type out all the code yourself and use the downloaded sample only for reference.

2.1 Before you start . . .

 
 
 

2.1.1 Planning the project

 
 

2.1.2 Understanding 3D coordinate space

 
 
 

2.2 Begin the project: Place objects in the scene

 
 
 
 

2.2.1 The scenery: Floor, outer walls, and inner walls

 
 
 

2.2.2 Lights and cameras

 
 
 
 

2.2.3 The player’s collider and viewpoint

 
 
 

2.3 Make things move: A script that applies transforms

 
 
 

2.3.1 Visualizing how movement is programmed

 
 

2.3.2 Writing code to implement the diagram

 
 
 

2.3.3 Understanding local vs. global coordinate space

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest