Chapter 9. Managing Object States and Controlling Their Movements

In this chapter, we will cover the following:

  • Controlling cube movement with player controls
  • Controlling object look-at behavior
  • Controlling object-to-object movements (seek, flee, follow at a distance)
  • Controlling object group movement through flocking
  • Firing objects by instantiation with forward velocity
  • Finding a random spawn point
  • Finding the nearest spawn point
  • Following waypoints in a sequence
  • Managing object behavior with states
  • Managing complex object behavior with the state pattern

Introduction

Many games involve moving computer-controlled objects and characters. For some games, animation components can be sufficient for all such movements. However, other games use directional logic—simple or sophisticated artificial intelligence involving the computer program that makes objects orient and move towards or away from the player or other game objects and characters. This chapter presents a range of such directional recipes, from which many games can benefit in terms of a richer and more exciting user experience.

Unity provides sophisticated classes and components, including the Vector3 class, and rigid body physics for modeling realistic movements, forces, and collisions in games. We make use of these game engine features to implement some sophisticated non-player character (NPC) object movements in the recipes of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.32.67