A* Pathfinding Project  4.2.2
The A* Pathfinding Project for Unity 3D
Movement scripts

Brief overview of the different movement scripts in the package.

There are several movement scripts included in the package. These are the scripts that actually move some object in your scene along a path, usually a character of some sort. The movement scripts primary role is to take care of searching for paths and following them.

These scripts are completely optional in this package, you can use pathfinding without using a movement script, or you can write your own movement script. However for many games they provide a nice base to build your characters on, even if you perhaps later in development replace them with something specifically tailored for your game.

There are three included movement scripts in the package AIPath, RichAI and AILerp. The names of the scripts could in hindsight definitely have been chosen better, but I'm hesitant to change them at this point as a large quantity of support material and forum posts refer to these names.

The primary differences between the movement scripts are:

AIPath

  • Good all-around movement script which works on all graph types.
  • Follows paths smoothly and responds to physics.
  • Works well with local avoidance.
  • Supports movement in 3D games as well as 2D games.

RichAI

  • Designed specifically for navmesh/recast graphs and does not work with any other graph types.
  • Better than the AIPath script at following paths on navmesh based graphs, it can handle getting pushed of its path better and usually follows the path more smoothly.
  • Has better support for off-mesh compared to AIPath.
  • Works well with local avoidance.
  • Supports movement in 3D games (movement in the XZ plane), but not 2D.

AILerp

  • Uses linear interpolation to move along the path (which is why 'lerp', which stands for linear interpolation, is in the name), does not use physics in any way.
  • Follows the path exactly, without any deviations whatsoever.
  • Due to the above points it does not make sense to use it with local avoidance, and thus it does not support it.
  • By far the fastest of the movement scripts, because the movement in itself is much simpler, but keep in mind that if you need any kind of physical realism in the game, you should usually use one of the other movement scripts.
  • Supports movement in 3D games as well as 2D games.

In short, if you are using a navmesh-based graph: use the RichAI script, otherwise use either AIPath or AILerp depending on what kind of movement style your game needs. Check out the example scenes included in the package to see how the different movement scripts behave.

All movement scripts included in the package implement the Pathfinding.IAstarAI interface. So if you need something that can interact with several different movement scripts, this is a nice interface to use.

For example these are some properties which you may find useful (these properties exist on all movement scripts):

See also
Pathfinding.IAstarAI

If you want your character to follow a specific object you can use the included script AIDestinationSetter. This will behind the scenes simply set the destination property every frame to the position of your chosen target.