How do I determine what place a player is in for a racing game.

0 favourites
  • 8 posts
From the Asset Store
Top Down Racing Game Pixel Artwork for any kind of racing game you can imagine.
  • Im making a racing game and im trying to figure out how to add a position system to show that place a player is in. ATM I have a checkpoint system that adds 1 to a total number for a player but i cant find a way to determine what place a player is in with it. pls help

    Tagged:

  • How about additionally checking the distance between the previous and the next checkpoint?

    distance(player.X,player.Y,prevCheckpoint.X,prevCheckpoint.Y) / distance(prevCheckpoint.X,prevCheckpoint.Y,nextCheckpoint.X,nextCheckpoint.Y)

    This gives a value between 0 and 1 as how far the player is between the checkpoints, e.g. 0.78 (= 78%)

    You add the number you already have that gives +1 per checkpoint and add to this the number between the checkpoints. The player with the higher number is further along the track. Like player X has checkpoint 2 and is 55% along the track = 2.55 and player Y has checkpoint 2 and is 54% along the track = 2.54.

    EDIT: You probably want quite a bunch of checkpoints for this to work properly, especially when there are many curves involved. Here is a checkpoint map from mario kart for reference.

    EDIT2: You probably need to check for shortest distance rather than distance to the origin point especially at the finish line where it really matters to be exact... Not 100% sure how that works but I guess the player that passes it first wins should do the trick aswell.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey thanks for the quick reply this was very helpful, but i'm still not really sure if how i can say the player with the highest number would be in first. I tried using a list to order the places but you can only use strings. Is there a way for me to do this?

  • With an array perhaps?

  • Here is my idea -

    When a car crosses a checkpoint (and checkpoint ID is greater than the previous one), save two instance variables for this car - checkpoint number and the time.

    So, for example, when there are two cars which both have crossed checkpoint #7, you can tell which one is ahead by picking the car with the lowest crossing time.

    To build a real-time leaderboard you can do something like this:

    For Each Car ordered by (Car.checkpoint*10000 - Car.crossingTime) Descending

  • Have you checked the Race track example ?

    It actually does pack such a ranking system with checkpoints.

  • Have you checked the Race track example ?

    It actually does pack such a ranking system with checkpoints.

    You need to push these much more, nobody thinks about checking these for some reason :D Maybe if someone makes a thread and mentions a XYZ game hint that there is an example project to check out (like you do with similar threads)

    I just took a quick glance at it but it seems to be similar to what I described. Cool!

  • Man i completely forgot about this post. I hadn't figured out a way to fix it so i kinda left it for a bit but then i went back to it and remembered the post. I didn't know that there were such test projects. so I will definitely check it out. So thank you all so much! lol

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