How to Create Smooth Movement Between Multiple Waypoint Targets When Using AIPath?

Hello,

I wrote a class that extends AIPath to allow for easily creating patrol routes. Basically the child class has an array of ordered Transforms that the class will target, in order, one at a time to cause the character to follow a given patrol route. The child class just simplifies doing things like setting the patrol route to Loop or PingPong via the inspector. The problem I have run into is when I want the character to smoothly move from target to target (i.e., waypoint to waypoint).

The way I have it setup right now is that I overloaded the OnTargetReached() method. When that is called I know my character has reached a waypoint. I then increment the waypoint counter and set the target to the next waypoint transform. This works great but the character stops after reaching each waypoint before moving to the next. Sometimes this is the desired behavior but I also want to be able to enable smooth movement between waypoints.

I thought I could do this by setting the “End Reached Distance” to cause the OnTargetReached() method to trigger a little earlier and thus set the target to the next waypoint before the character stops moving but it turns out (after reading the documentation) that once “End Reached Distance” is reached, all movement stops (even if you’re short of the target position). As a result, this doesn’t really work.

Is there a way using the base AIPath class to get the desired behavior? Basically I need a version of OnTargetReached() that triggers once the character is within a certain distance of the target. Is there a simple way to test for something like this that is fairly performant? Thank you!

~Sarus

To get good smooth patrolling, I don’t think you can just extend AIPath. Because to get smooth movement, you would want to smooth the turns between the waypoints (I guess), and then you are better off modifying the script itself, or writing a custom one.
What you also would need to do is to calculate one path before it actually starts following it so that when it reaches the point where it switches waypoint target, it already has that path calculated and ready to go. If you do not do this, you will end up with a few frames when the unit does not move at all (which is what you see now).