Check whether car has passed a point in world space


I’m developing a racing game and currently working on a reinforcement learner for my car AI. I got it working for an early version of my car prefab (had a fairly slow top speed of 60mph).

I have since updated my car prefab to have a higher acceleration and top speed (now 120mph).

Now for the problem:

The car is driving around the track based on points on a spline generated from several waypoints positioned around the track (throttle and steering values are learned over thousands of iterations between each point on the track).

This worked fine for the first prefab which had a relatively low speed; I was checking the magnitude of the vector between the car and the point and if this was under a threshold (ie 2.0), then move on to the next spline point.

Now the car is at a higher speed, however, this check is sometimes skipped as the car moves past it too quickly. As such it ends up crashing as it is still trying to steer/throttle towards the point.

I’m struggling to think of possible solutions to this. One potential one I came up with may be to create simple box colliders at each spline point with continuous dynamic collision detection and use that to check if the car passes through it, but I feel this may be a bit of a hacky solution.

Does anyone have any suggestions/encountered something like this before?

Sorry for the wall of text :slight_smile:

TL;DR: Car moving too fast to check if it has passed through a point on a spline, how can I test for this better?

The collider solution sounds quite good actually. It was just what I was going to suggest based on the title.

As for sticking to the original spline idea… well, do you need to compare it to just those determined points? Assuming you have a whole spline structure in place and you can just extrapolate any point, wouldn’t it work to check what the closest point to the car is, and then moving the car towards a point that is a set distance along the spline? (Maybe increase this set distance based on speed)