Player control of a 3D GameObject (and limiting movement within a rectangle)
Many of the 3D recipes in this chapter are built on this basic project, which constructs a scene with a textured terrain, a Main Camera
, and a red cube that can be moved around by the user with the four directional arrow keys:
Figure 11.5: Basic 3D scene with a player-controlled cube
The bounds of movement of the cube will be constrained using the same technique that we used in the previous 2D recipe.
Getting ready
For this recipe, we have prepared the image you need in a folder named Assets
, in the 10_02
folder.
How to do it...
To create a basic 3D cube-controlled game, follow these steps:
- Create a new, empty Unity 3D project.
- Import the single Terrain Texture named
SandAlbedo
from the10_02
provided folder, in theAssets
folder. - Create a new terrain by going to GameObject | 3D Object | Terrain.
- With this new Terrain GameObject selected in the Hierarchy...