# Any good ideas on how to get the "ideal line" of a track?

This topic is 971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So the aproach I', creating my track at the moment is simmilar to 3d lofting, the track is a list of Segments, each segment has sideA, sideB and a center node.

?I created an AI algorythm that almost mimics the racing line behaviour, but at straights it centers  to the track which is not that "ideal". So I figured why not add an ideal line node to the segmet aswell, so the AI can actually follow these points.

?In real life I know how a raceline is formed, but I would like to create a script that auto populates these "ideal nodes". So ideas are welcome.

?Here's an image of showing what I'm after.

So according to the image, to draw the racing line, it needs to start from the outside of the track, go inside near apex and exit outside again. I've got a feeling that this is achievable with a DotProduct trick. Am I right?

##### Share on other sites

A dot-product trick? I was thinking of some dynamic programming and optimal control, but perhaps that's way more trouble than you are willing to go through.

A similar approach would be to train a neural network using DQN.

##### Share on other sites

?I'm down to find something similar to this. As far as my mind can figure, is that the raceline is calculated from current and next waypoint, not entirely sure how that's the reason I posted here. Neural network seems interesting, but I like to keep the code as simple as possible.

##### Share on other sites

I've done something similar like in the video for a simple cell phone race game.

Can't remember exactly, but i think i have used two variables:

How far to look ahead - the red line in the video, this is to set the steering angle.

How fast to drive.

Those values have been stored in arrays, e.g. one entry each meter.

Tha car started slowly and tried to get faster each round, alternating the values in the arrays and comparing with previous results to go back eventually.

After 1000 rounds the results were very good, i was unable to beat it driving manually.

Maybe that's a very simple form of a neural network.

##### Share on other sites

Maybe that's a very simple form of a neural network.

Not quite, but it's a form of learning, so it's in the same class of solutions.

##### Share on other sites

How far to look ahead - the red line in the video, this is to set the steering angle.

?This is something that I do at the moment, I'm making the AI to look ahead to get the next waypoint and then set the steering with a small offset factor that is calculated with the sections angle to get some more precise "racing line" feel, but this method actually makes the same mistakes for every driver at same corners, because there is no actual racing line to follow.

i yh?And OT. w

Exactly, why is the forum doing such tricks??? I press enter go to a new line, write something and boom, it's back on the start of the line, you dont imagine how many times I have rewriten my posts because of this bug. In case what i ment with "i yh?And OT. w", it was ment to be And OT.(Off topic) why i... this is just stupid, what ever is refreshing the forum, make it stop lol. I want to speak about AI not the bugs of this forum

##### Share on other sites

Those values have been stored in arrays, e.g. one entry each meter.
Tha car started slowly and tried to get faster each round, alternating the values in the arrays and comparing with previous results to go back eventually.
After 1000 rounds the results were very good, i was unable to beat it driving manually.
Yeah I've seen a similar thing at an old job. IIRC we started with a guess of the racing line (it might have been the centre line of the track - though the OP's algorithm would be a better starting guess) and then the AI chose to deviate left or right of the line at random. When they set a lap record, their deviations became the new racing line. You'd spawn 30 cars on the track and leave them to drive for a while, and come back to a sensible looking racing line :)

##### Share on other sites

I'm making the AI to look ahead to get the next waypoint and then set the steering with a small offset factor

Waypoints might not be ideal.

For me the track was made from a big spline with many control points, but straight lines would work the same way:

The car calculated the closest position to the spline, expressed as t = 0 for start and t = 1 for finish.

Steering target was calculated from t + learnedLookAheadNumber, and learnedLookAheadNumber was interpolated from the closest array entries using t as well.

The benefit is that everything is smooth by default with little affort - no snapping behaviour like in the video.

I assume it's easier to learn the ideal racing line and speed under smooth conditions.

##### Share on other sites

I have an interesting idea, could Projectile Trajectory do the trick?

##### Share on other sites

I agree that's interesting.

Projectile trajectory comes from constant acceleration, and i use a control system that switches between constant acceleration / deacceleration at the right time to hit a target for various physics problems (not related to driving).

I'd try something similar like this if i had to make a 'realtime' driving ai, while the suggested approach above is simple precalculation working only for static tracks.

The problem is, i doupt it's possible to get a reasonable accurate solution for complex vehicle dynamics and tweaking approx. methods is lots of work.

At the and a bit of both might work best - precomputing the track driving, and some dynamic ai for opponent cars.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013294
×