I have two solutions. Both of them rely on treating the path not as a path per-se but as a trajectory. What you want is for your agent to move such that at each point in time, the agent is close to the path, and his velocity is along the path. So, you've got to add another dimension to your path: time. You can turn your static path into a function that says "where should I be at time t?" the agent then tries to get to the point "where he should be". This is called a trajectory.
The easy solution:
- Take the entire trajectory as a single curve paramaterized by time t between 0 and 1. Create a function which goes from [0,1] to a 3D point f(t).
- The agent starts at t = 0. He seeks the point f(t) until he's within a radius (called the blend radius).
- t then advances by a small amount.
The better solution:
- Start again with a trajectory paramaterized by a single number between 0 and 1.
- Find t_x such that the distance between the agent and the trajectory is minimized. (If you trajectory is piecewise linear, this involves projecting to the nearest line)
- Seek the point f(t_x + e) where e is a small number representing the "lookahead time". e can be larger the further away the agent is from the trajectory.
I also have source code and a graphical example for the second solution: