- Home /
Check whether car has passed a point in world space
Hello!
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 :)
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?
Answer by Oana · Jul 02, 2013 at 12:51 PM
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)
Yeah I'm in the process of trying the collider method now, if that proves to work well I may just stick with that. $$anonymous$$y main concern is if theres much of a performance hit using so many colliders?
If not your proposed alternative sounds like it would work, though definitely require a large amount of reworking in the code.
$$anonymous$$any thanks for your help!
Your answer
Follow this Question
Related Questions
How To Add AI To Car/Racer? 4 Answers
Car- can someone help me convert this to C#? 1 Answer
Steering an AI vehicle to a waypoint using float of -1 to 1? 1 Answer
Cars in City 0 Answers
Can not get value out of a collision 1 Answer