Questions about custom movement script

Hi,
while learning from the version 5.1.4 ‘Writing a movement script’ documentation, I have 2 questions here.

  1. there is no code to explicitly “stop the path finding”. I was expecting path = null or path.dispose() calls after the speedFactor is nearly zero. Is this not neccessary or just not in the scope of the tutorial?

  2. I suspect the move might overshoot. So say when distanceToWaypoint = 0.1 it’s either 0.1 to the point or 0.1 pass the point. Any suggestions to prevent from overshooting?

by the way my purpose is writing a custom movement script for 2D topdown game based on grid graph
Thanks

It’s not a problem to keep the path even after the agent has reached its destination.
In fact, it is very useful if local avoidance is used, since then the agent might get pushed away from its destination and will need to recover.

The built-in movement script use various approaches to do this more robustly. For example the AIPath script uses the PathInterpolator class (the documentation page for that class seems to be partially broken, it’s missing a lot of stuff. I’ll look into that, but check the script file itself for docs). It always moves towards a point where the path intersects a circle around the agent.
aipath_variables

I do recommend testing the built-in movement scripts first to see if you can use those directly.

1 Like