W
W
Way2017-06-21 10:19:55
Java
Way, 2017-06-21 10:19:55

How to calculate the position of a player in a race?

Good afternoon! I am writing a small mini-game in the "Racing" genre and ran into a problem, I need to somehow get the position of the player (racer) during the race. How can this be done? There are only three options in mind:
1. Each checkpoint check the position of the player among all
2. Check the position of the player relative to the finish line
3. Check the distance of the player between other players.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2017-06-21
@YouTy6bl4

If I understand correctly, you need to know who is first, who is second, and so on.
You can decide not so much by position - but by time (it looks like the first option with checkpoints will be)
Crossing the checkpoint - it counts how many seconds from the start of the race it took to "reach this point" and we will also get data on how much they lag behind each other. as in rally and other races
there will be a sign ala
Car1 - 1:23:234+0:00;
Car2 - 1:24:734+1:50;//one and a half seconds behind/later reached
Car2 - 1:25:734+2:50;//2.5 seconds behind the leader
and then by analogy.
You can count not from the leader, but from yourself. then everyone who has reached the checkpoint in front of you will have a minus increase in time - an indicator of how much they overtake you.
And you can check the distance only if your track is straight, or there is a curve passing along the track (and you can calculate not directly the distance, but how much you need to drive along the curve).
Otherwise, there is a problem on sharp turns and bends and with guys lagging behind in a circle)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question