Fundaments of Game Design Unity Terrain Trees and

  • Slides: 14
Download presentation
Fundaments of Game Design Unity Terrain, Trees and Navmesh Richard Gesick

Fundaments of Game Design Unity Terrain, Trees and Navmesh Richard Gesick

Objectives • Unity terrain • Unity vegetation/trees • Navmesh and navigation 1 -2

Objectives • Unity terrain • Unity vegetation/trees • Navmesh and navigation 1 -2

Unity Terrain • Unity’s terrain system allows you to add vast landscapes to your

Unity Terrain • Unity’s terrain system allows you to add vast landscapes to your games. At runtime, terrain is highly optimized for rendering efficiency while in the editor, a selection of tools is available to make terrains easy and quick to create. • A Terrain Game. Object adds a large flat plane to your scene and you can use the Terrain’s Inspector window to create a detailed landscape 1 -3

Creating and editing Terrains • To add a Terrain Game. Object to your Scene,

Creating and editing Terrains • To add a Terrain Game. Object to your Scene, select Game. Object > 3 D Object > Terrain from the menu. • This also adds a corresponding Terrain Asset to the Project view. • When you do this, the landscape is initially a large, flat plane. • The Terrain’s Inspector window provides a number of tools you can use to create detailed landscape features. 1 -4

Tools • The paint brush in the terrain toolbar is used to raise and

Tools • The paint brush in the terrain toolbar is used to raise and lower the terrain height, paint the terrain texture and paint trees. • Trees are solid 3 D Game. Objects that grow from the surface. Unity uses optimizations, like billboarding for distant Trees, to maintain good rendering performance. This means that you can have dense forests with thousands of trees and still keep an acceptable frame rate. • Unity has several tree types in Standard Assets. 1 -5

Grass and other details • A terrain can have grass clumps and other small

Grass and other details • A terrain can have grass clumps and other small objects such as rocks covering its surface. • Grass is rendered by using 2 D images to represent the individual clumps while other details are generated from standard meshes. 1 -6

Navigation System in Unity • The Navigation System allows you to create characters which

Navigation System in Unity • The Navigation System allows you to create characters which can navigate the game world. It gives your characters the ability to understand that they need to take stairs to reach second floor, or to jump to get over a ditch. The Unity Nav. Mesh system consists of the following pieces: • Nav. Mesh Agent • Off Mesh Link • Nav. Mesh Obstacle 1 -7

Navigation Mesh and agent • Nav. Mesh is a data structure which describes the

Navigation Mesh and agent • Nav. Mesh is a data structure which describes the walkable surfaces of the game world and allows to find path from one walkable location to another in the game world. The data structure is built, or baked, automatically from your level geometry. • Nav. Mesh Agent component helps you to create characters which avoid each other while moving towards their goal. Agents reason about the game world using the Nav. Mesh and they know how to avoid each other as well as moving obstacles. 1 -8

Off mesh link • Off-Mesh Link component allows you to incorporate navigation shortcuts which

Off mesh link • Off-Mesh Link component allows you to incorporate navigation shortcuts which cannot be represented using a walkable surface. For example, jumping over a ditch or a fence, or opening a door before walking through it, can be all described as Off-mesh links. 1 -9

Nav. Mesh obstacle • Nav. Mesh Obstacle component allows you to describe moving obstacles

Nav. Mesh obstacle • Nav. Mesh Obstacle component allows you to describe moving obstacles the agents should avoid while navigating the world. • A barrel or a crate controlled by the physics system is a good example of an obstacle. • While the obstacle is moving the agents do their best to avoid it, but once the obstacle becomes stationary it will carve a hole in the navmesh so that the agents can change their paths to steer around it. • If the stationary obstacle is blocking the path way, the agents can find a different route. 1 -10

Building a Nav. Mesh • The process of creating a Nav. Mesh from the

Building a Nav. Mesh • The process of creating a Nav. Mesh from the level geometry is called Nav. Mesh Baking. The process collects the Render Meshes and Terrains of all Game Objects which are marked as Navigation Static, and then processes them to create a navigation mesh that approximates the walkable surfaces of the level. 1 -11

Building a Nav. Mesh • Nav. Mesh generation is handled from the Navigation window

Building a Nav. Mesh • Nav. Mesh generation is handled from the Navigation window (menu: Window > AI > Navigation). • Building a Nav. Mesh for your scene can be done in 4 quick steps: 1. Select scene geometry that should affect the navigation – walkable surfaces and obstacles. 2. Check Navigation Static on to include selected objects in the Nav. Mesh baking process. 3. Adjust the bake settings to match your agent size. – – Agent Radius defines how close the agent center can get to a wall or a ledge. Agent Height defines how low the spaces are that the agent can reach. Max Slope defines how steep the ramps are that the agent walk up. Step Height defines how high obstructions are that the agent can step on. 4. Click bake to build the Nav. Mesh. • The resulting Nav. Mesh will be shown in the scene as a blue overlay on the underlying level geometry whenever the Navigation Window is open and visible. 1 -12

Creating a Nav. Mesh Agent • Create a cylinder: Game. Object > 3 D

Creating a Nav. Mesh Agent • Create a cylinder: Game. Object > 3 D Object > Cylinder. • The default cylinder dimensions (height 2 and radius 0. 5) are good for a humanoid shaped agent, so we will leave them as they are. • Add a Nav. Mesh Agent component: Component > Navigation > Nav. Mesh Agent. • Now you have simple Nav. Mesh Agent set up ready to receive commands. When you start to experiment with a Nav. Mesh Agent, you most likely are going to adjust its dimensions for your character size and speed. 1 -13

Creating a Nav. Mesh Agent • The Nav. Mesh Agent component handles both the

Creating a Nav. Mesh Agent • The Nav. Mesh Agent component handles both the pathfinding and the movement control of a character. In your scripts navigation can be as simple as setting the desired destination point the Nav. Mesh Agent can handle everything from there on. 1 -14