How to do it...

To make an NPC to travel to a destination while avoiding obstacles, follow these steps:

  1. Create a new, empty 3D project.
  2. Create a new 3D Terrain, choose menu: Create | 3D Object | Terrain. With this new Terrain GameObject selected in the Hierarchy, in its Inspector properties set its size to 30 x 20, and its position to (-15, 0, -10) so we have this GameObject centered at (0,0,0).
  3. Texture paint this terrain with the SandAlbedo texture.
  4. Create a 3D Capsule named Capsule-destination at (-12, 0, 8). This will be the target destination for our NPC self-navigating GameObject.
  5. Create a sphere named Sphere-arrow that is positioned at (2, 0.5, 2). Scale it to (1,1,1).
  6. Create a second sphere named Sphere-small. Scale it to (0.5, 0.5, ...

Get Unity 2018 Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.