How do I rank/position for a race game

  • 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

  • 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.

  • 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?

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.........

  • > 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

  • You might find this interesting.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)