Jump to content

Genre specific algorithm: Racing game positions


RygtY
 Share

Recommended Posts

Hi I want to ask something that I can't quite figure out on my own.

 

How does a racing game keep track of who is 1st, 2nd, 3rd, and so on and so forth and update that information on the fly?

 

Also this algorithm must work for any track of arbitrary topology.

Link to comment
Share on other sites

I would place pivots throughout the scene to make a track, and count the times each car has passed the waypoint. The AI would aim the car at the next waypoint, then count it as "crossed" once it gets within a certain distance. I've actually been thinking about this because I want to make a racing game template to include in the software.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Hi

here what i did for my game (still in work...)

 

as Josh said and depends on the precision you want ( i put a pivot each loop):

1) put a pivot where the car is before starting

2) once started first loop calculate the distance between the new pos car and the pivot and substract the distance to next waypoint

3) put the pivot where the car is now and calculate the raced distance and you have the first position car

4) keep a track of the distance by car to calculate the entire track

 

it is tricky because if some car goes far away very speedy it will be the first by pure raced distance but with the waypoint distance substracted, it is more accurate.

something like this working good for me though.

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

Hi

here what i did for my game (still in work...)

 

as Josh said and depends on the precision you want ( i put a pivot each loop):

1) put a pivot where the car is before starting

2) once started first loop calculate the distance between the new pos car and the pivot and substract the distance to next waypoint

3) put the pivot where the car is now and calculate the raced distance and you have the first position car

4) keep a track of the distance by car to calculate the entire track

 

it is tricky because if some car goes far away very speedy it will be the first by pure raced distance but with the waypoint distance substracted, it is more accurate.

something like this working good for me though.

 

I really cannot read things in the list that you just typed.

 

Could you please say it again?

 

EDIT: Sorry, I've noticed that you are from France. If possible could you post the same concept but written in French, so that there is reference to translated from.

Link to comment
Share on other sites

Ok so, my english is rusty...

 

1) Avant le départ de la course, je place un pivot à l'endroit de la voiture.

2) Une fois la course partie, (premier loop) je calcule la distance entre le pivot et la position de la voiture au premier loop et je soustraie cette distance à la distance entre la voiture et le waypoint suivant.(ce qui me donne la distance restante à faire jusqu'au prochain waypoint)

3) Je replace le pivot (placé en 1) à la position actuelle de la voiture pour le prochain calcul au loop suivant.

je fais ceci pour tous les véhicules et la distance restante la plus petite me donne la place du premier, 2eme,3eme...etc

4) Je garde les distances effectuées dans un tableau pour connaitre la distance effectuée sur un tour.

 

voila je pense avoir été clair,

hope it helps and sorry for my english ;)

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

How I did it for a different game I made:

 

Setting up:

1: Have pivots set up as waypoints. This is also useful to see if people actually did race the entire track.

2: Whenever a player is near the next waypoint (using a distance check), add 1 to the waypoint variable. Reset the variable to 0 whenever the player is back at the start. The waypoint variable displays how many waypoints it has passed.

 

Algorithm:

1: First check the amount of laps, sort by that

2: Secondly, sort by amount of waypoints

3: At last (if needed), do a distance check towards the next waypoint

 

So for example:

Car 1 finished 2 laps and is at waypoint 2

Car 2 finished 1 lap and is at waypoint 8 and is 5 meters from the next waypoint

Car 3 also finished 1 lap and is at waypoint 8 and is 15 meters from the next waypoint

 

Car 1 is first place because it has more laps

Car 2 is second place because even though he has completed as many waypoints as Car 3, he is closer to the next waypoint.

  • Upvote 2

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...