how to choose which waypoint next?

Blitz3D Forums/Blitz3D Beginners Area/how to choose which waypoint next?

What you are doing is fine. The way you are storing them is fine (x, y, z) - I'd store the lane they are in too - this will make it easy when making them overtake.

Start simple (an oval track is ideal) - make the cars favour the inside line this forces the idea that they only need to change lanes to overtake.

So, if you are driving a car on the track on the inside lane (driving slowly on purpose) and a CPU AI car comes up behind you - allow the AI to check your speed compared to theirs - ie assist the AI - you can also use EntityDistance too.

Once EntityDistance is so close, and the car in front is going slow enough to overtake, let your AI car pick a forthcoming waypoint in Lane 2 - make sure the waypoints are not too close together to allow it to swing out before getting to the waypoint. The next waypoint can be the same waypoint number as the current lane, but you just make sure it picks lane 2. Remember to make them move back to the inside - again using EntityDistance, etc.

You can also use overtaking waypoints - in real-life racing, some circuits have good overtaking spots on them so feel free to give the waypoints an 'overtaking value' - you can rate these say 0 to 5 - 0 being void (ie a default waypoint) and then 5 being the highest valued one where an AI driver will try to overtake when they hit it - ie they have just reached the waypoint (and if there is something in front and the EntityDistance is low enough) then let them go for the overtake.

Start simple and build the AI up - there isn't much need to make them overtake randomally unless you are using a track that is not oval-like and widens and narrows - personally, I'd recommend starting simple.