Following behavior

The most basic AI-controlled follow behavior is available as a simple function node. All you have to do is perform the steps that follow to get one AI-controlled unit to follow a unit or object.

Getting ready

Have a UE4 project ready with a simple landscape or set of geometry on the ground— ideally, with a cul-de-sac somewhere in the geometry for testing out AI movement functions. Create a Nav Mesh over this geometry so that the AIMoveTo function will work as described in the previous recipe.

How to do it…

  1. Create a Nav Mesh for your level's geometry as described in the preceding recipe, Laying down a Navigation Mesh.
  2. Create a Blueprint class deriving from Character by finding the Character class in the Class Viewer, right-clicking on it, and selecting Create Blueprint Class…
  3. Name your Blueprint class BP_Follower.
  4. Double-click on the BP_Follower class to edit its Blueprint.
  5. In the Tick event, add an AIMoveTo node, which moves towards the player pawn (or any other unit) as follows:
    How to do it…

How it works…

The AIMoveTo node will automatically use a Nav Mesh if one is available. If a Nav Mesh is not available, then the NPC unit won't move.

There's more…

If you do not want the unit to move with pathfinding using the Nav Mesh, then simply use a Move To Location or Actor node.

There's more…

A Move To Location or Actor node works even without a Nav Mesh on the geometry.

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

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