Car bot that follows waypoints

Hello,

I’m making a simple racing game using the vehicle API in PlayCanvas, and am currently trying to create a bot that doesn’t rely on input but follows some waypoints rather. The throttling part to make the vehicle move is done and works, but what I’m having a hard time with is steering. I can’t figure out a way to get the right amount of value to steer, may it be left or right depending on the road, in order for the car to follow the waypoints (the road) properly.

I tried having the vehicle position and target position substracted in math.abs, then use the value to lerp from 0 to that, and then use the lerp result to add to the steering value.
Another method was using the dot operator to find the angle between the two vectors (normalized), then acos(dot), radian to degree, clamped the result between -1 and 1, and used the value to add to the steer.
Both of which didn’t give the desired output. Also tried some minor changes here and there, like the order of the variables and some conditions (out of desperation), but to no avail.

If someone has an idea on how this would work, I’d very much appreciate it.
Thank you in advance.

Hi @ArianitMujaj and welcome,

You could use bezier curves to describe a curved path between waypoints, this way you will get much better steering behavior from your AI bots when navigating around waypoints.

You will have to re-evaluate the path each time there is a collision with another car or a dynamic obstacle.

1 Like