Menu

Tutorial #2: Adding Waypoints

Untitled 20

In this tutorial, we will be adding onto the previous tutorial’s scene.  However, it can also serve as a quick reference on how to add waypoints, so the previous tutorial is not needed.

You will learn:

 

STEP 1:  Drag the “WaypointRoute” prefab into your scene. It is located in the folder “/Waypoint System”

1

 

 

STEP 2: Open the WaypointRoute hierarchy and delete the last 3 sample waypoint markers.

2

 

 

STEP 3: Reset the remaining WaypointMarker local position to 0,0,0.  This helps you locate the marker in the editor window.

3

 

 

STEP 4: The WaypointMarker represents a single target destination for the A.I.    So drag the marker to a location you want the bot to move to.  Here, let’s drag it to a corner.

4

 

 

STEP 5: Now we’re going to create more waypoints.  Simply copy/paste or duplicate the first waypoint marker. Make sure all waypoints are set as a child of the “WaypointRoute” prefab.

5

 

 

STEP 6: Drag the new waypoints into new destinations.  Here, we drag them into corners.  Notice that a line automatically connects them in the editor.  This is the route the bot will follow.

6

 

 

STEP 7:  You’re done setting up waypoint route.  Now, we will tell the bot to process this waypoint system.  Click the AI Bot and find the Movement FSM.  Find the FSM variable “charROLE_PatrolWaypoints”.  Simply drag the “WaypointRoute” gameobject into that slot.  That’s it! Now the bot will process that waypoint.

Tip: If you noticed, FSM variables can all be modified at run time. This means you can even dynamically change the bot’s waypoint system to patrol another route at run time!  You are allowed to have unlimited “WaypointRoute” objects in the scene, each with unlimited waypoints!

7

 

 

STEP 8:  But what should the bot do with the waypoint system? Should he patrol it? Go in reverse? Pick random waypoints?  Now you have to tell the bot what to do with the waypoints.  Simply find the bot’s Tactics FSM.  Find the FSM variable “TACTICS_CurrentCommand”.  Set it to PATROL_WAYPOINT  (must be ALL CAPS, no spaces).  This will tell the bot to patrol the waypoint system in order.

8

 

 

STEP 9: You’re done! Now play the scene. If you did it right, the bot should patrol the waypoints.  If you get NavMesh errors, you must bake the NavMesh before playing.

 

OTHER PATROL COMMANDS:  We have 3 patrol commands built in.  They can be found in the section called “Bot Commands”  You can try these other 2 out as well:

PATROL_WAYPOINT_PINGPONG

9

 

 

PATROL_WAYPOINT_RANDOM

10