Strange AI

Hi all, I’m using a waypoint system for my racing AI, and am using triggers to determine if the racer has reahed a waypoint. The AI takes the position of the targeted waypoint and localizes the position. If the position of x is less than 0, it turns left; if it is more than 0, it turns right. However, sometimes the AI turns away from the waypoint without being hit or affected and crashes into the wall, and just stays there, and keeps going forward, even though the wall and it has zero friction (can turn along the wall) and the waypoint is just a few meters left from it. Sometimes, it turns but goes back the wrong way of the track. What can be done to solve this?

Many thanks!

You are facing one of those problems that can be solved with infinite solutions ranging from one-line-simple to impossibly-complicated, so it can be difficult to pinpoint a cause for the issue.

Anyways, my guess is that the ‘direction algorithm’ you’re using is only called upon the waypoint trigger, right? Whilst you should instead call it repeatedly over time to be sure that no external event misleads the ai and sends it forever into the wrong direction.

For that you could use the ‘InvokeRepeating’ function.

Have you considered using UnitySteer (a porting of OpenSteer)? It has a Vector3PathWay defining a set of waypoints and a SteerForPath behaviour that can control your AI.