Sign in to follow this  
WhateverMan

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

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.

corner_racing-line-traditional.gif?b63ce

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 this post


Link to post
Share on other sites

A dot-product trick? I was thinking of some [url="http://www.athenasc.com/dpbook.html"]dynamic programming and optimal control[/url], 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 [url="https://deepmind.com/dqn.html"]DQN[/url].

Share this post


Link to post
Share on other sites

https://www.youtube.com/watch?v=_XKphuYviE0
?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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

I Did some GeoGebra magic today and found some usefull information, tho I'm not entirely sure on how to get the same information in Coding wise. ?As I thought I have to make use of DotProduct and CrossProduct. With DotProduct I can easly create scalar projections of Perpendicular points Using this formula:

 

ap = p - a
?ab = b - a

sp = dot(ap,ab.normalized)
 

where:
  • ap is the vector from a to p
  • ab is the vector from a to b
  • sp is the scalar projection of p on ab (float)
 
to get the actual normal point on ab we can write
normalPoint = a + (ab.normalized * sp)
 
Now the Cross product is the bit I dont quite get yet, it always seems to be zero or simmilar to the normalPoint, any tips?

?On the chart, my simple questions are, how to find A1, B1 and T. (Basically they would be mapped on the waypoint node as "RacingLinePoint" but first the magic...

?Edit:
The radius of the racing line comes from this formula:
ArcR_radius =? (C1T / 2) + ((A1B1 * A1B1) / 8 * C1T)

The variables are on the graph..

Edited by WhateverMan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this