# How do I rank/position for a race game

Get help using Construct 2

### » 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
2
Posts: 34
Reputation: 584

### » 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.
B
87
S
26
G
75
Posts: 1,458
Reputation: 47,940

### » 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?
or in this thread Archer Devlog
B
50
S
22
G
19
Posts: 1,144
Reputation: 14,855

### » 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
S
1
Posts: 20
Reputation: 464

### » 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:
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

### » 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
B
87
S
26
G
75
Posts: 1,458
Reputation: 47,940

### » Tue Mar 10, 2015 12:21 am

B
149
S
30
G
7
Posts: 1,103
Reputation: 14,477

### » 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.

Plus, if the Racer (bot or not) don't overlap the checkpoint, he will re-spawn before the checkpoint, avoiding shortcuts and cheats.
B
110
S
24
G
18
Posts: 1,391
Reputation: 23,017