RygtY Posted June 12, 2015 Share Posted June 12, 2015 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 12, 2015 Share Posted June 12, 2015 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. Quote 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 More sharing options...
diedir Posted June 12, 2015 Share Posted June 12, 2015 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. Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
nick.ace Posted June 13, 2015 Share Posted June 13, 2015 This does exactly what Josh said (with video tutorial): http://www.leadwerks.com/werkspace/page/viewitem?fileid=364622139 BTW, I don't really have time to expand this, so if anyone wants to contribute, let me know and I'll make you a collaborator. Quote Link to comment Share on other sites More sharing options...
RygtY Posted June 17, 2015 Author Share Posted June 17, 2015 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. Quote Link to comment Share on other sites More sharing options...
diedir Posted June 17, 2015 Share Posted June 17, 2015 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 Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
martyj Posted June 17, 2015 Share Posted June 17, 2015 I would actually make multiple privots around the track. That way you can detect if they went backwards through the starting position to re-cross the line. Quote Link to comment Share on other sites More sharing options...
f13rce Posted June 17, 2015 Share Posted June 17, 2015 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. 2 Quote 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 More sharing options...
diedir Posted June 18, 2015 Share Posted June 18, 2015 yes Evayr explained better than me, this is the idea, you must try that Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
Recommended Posts
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.