How do I rank/position for a race game

Get help using Construct 2

Post » Mon Mar 02, 2015 8:58 pm

hi im doing a minigame for my game and i want this to be a race, its just a straight line with another 4 competitors (AI)
So all i need to know is how to show in what places they are, so i can show them in which place is they are compared to the other ia competitors ( like 1st 2nd 3th place)
i hope you understand the question my english is very rusty
Thanks
B
8
S
1
Posts: 34
Reputation: 434

Post » Tue Mar 03, 2015 5:03 am

well take the distance from start of line and current position and measure it, if your player is first the distance will be bigger if its not the first but the 2nd then compare the distance that player has and the distance that the AI in first position has and say "if player has distance less then AI1 and bigger then AI2 and AI3 then set pos to 2 and so on. u have to do the math, and events alot of combinations, but with distance is 1 simple way to do it, take as A point to start measure the distance the startup line, and B point the end line, distance will be the space between them. :)
ImageImage
B
55
S
14
G
64
Posts: 1,259
Reputation: 39,571

Post » Tue Mar 03, 2015 9:52 am

Like gamecorpstudio said you could compare distances, but could be tricky in a circular or odd shaped race track? maybe you have to add a few hidden checkpoints, and check the distance to those? and when you pass one checkpoint check the distance to the next checkpoint?
Follow my progress on Twitter
or in this thread Archer Devlog
B
25
S
9
G
12
Posts: 615
Reputation: 8,150

Post » Mon Mar 09, 2015 10:15 pm

gamecorpstudio wrote:well take the distance from start of line and current position and measure it, if your player is first the distance will be bigger if its not the first but the 2nd then compare the distance that player has and the distance that the AI in first position has and say "if player has distance less then AI1 and bigger then AI2 and AI3 then set pos to 2 and so on. u have to do the math, and events alot of combinations, but with distance is 1 simple way to do it, take as A point to start measure the distance the startup line, and B point the end line, distance will be the space between them. :)


can you give an example?
B
6
Posts: 20
Reputation: 314

Post » Mon Mar 09, 2015 10:36 pm

have it so it lists the players names at the side of the screen with textbox's saying place:
Than add 0
player1 Place: 0
player2 Place: 0
player3 Place: 0
Than add an event so whoever crossing finish line first after 3 laps will get 1 by there name, 2nd gets 2. 3rd gets 3rd.........
B
3
Posts: 6
Reputation: 189

Post » Mon Mar 09, 2015 11:01 pm

ricardoguedes21 wrote:
gamecorpstudio wrote:well take the distance from start of line and current position and measure it, if your player is first the distance will be bigger if its not the first but the 2nd then compare the distance that player has and the distance that the AI in first position has and say "if player has distance less then AI1 and bigger then AI2 and AI3 then set pos to 2 and so on. u have to do the math, and events alot of combinations, but with distance is 1 simple way to do it, take as A point to start measure the distance the startup line, and B point the end line, distance will be the space between them. :)


can you give an example?



lets say u have car1 and car2 and point A for finish line
if car1 is at x 300

and car2 at x 150
u can compare two variables 1st variable to compare will be the distance from car1 to finishline and distance of car2 to finishline this is for straight drag races.(and u do next : |distance(car1.x,car1.y,finsihline.x,finishline.y)| < (less ) then next variable will be| distance(car2.x,car2.y,finsihline.x,finishline.y) | set car1.position to 1, set car2.position to 2(the position is your display rank u have in game , not the actuall position.) the logic is => if the distance from car 1 to finish line is smaller then distance of car2 to finish line, the car 1 will be positioned in first place , and car 2 to second place.


also for drag race , you could simple compare the X values only so if car1.x >(greater then ) car2.x then car1 is 1st place
ImageImage
B
55
S
14
G
64
Posts: 1,259
Reputation: 39,571

Post » Tue Mar 10, 2015 12:21 am

ImageImage
B
88
S
18
G
6
Posts: 1,048
Reputation: 11,128

Post » Tue Dec 06, 2016 12:55 pm

Again, because some people are asking me how do I solved it, I'm answering this old post instead of creating a new one to share the answer.

Thanks to @R0j0hound a long time ago, I have solved it differently.

Image

Plus, if the Racer (bot or not) don't overlap the checkpoint, he will re-spawn before the checkpoint, avoiding shortcuts and cheats.
ImageImageImageImageImageImage
Image
B
95
S
21
G
16
Posts: 1,337
Reputation: 20,975


Return to How do I....?

Who is online

Users browsing this forum: Braus, pinoyaida and 5 guests