Johnny Shumway
Johnny Shumway

Reputation: 24

How would I keep track of the Player and AI's positions for a racing game?

Summary:

So, as the question suggests I'm trying to develop a racing game. Although, I need to create a system to keep track of what positions the Player and AI are in. Positions as in first place, second place, third place, etc.

What I've tried:

At first I was going to use a system that was made by Jimmy Vegas in one of his tutorials for developing a racing game, but this system only works with two cars and an enclosed track/circuit. My game is an off road racing game, this means the track is open and the player will be able to make there own shortcuts and no walls will restrict the player's ability to roam the map. This renders Jimmy Vegas's system useless for my type of racing game. I tried to mess around with the code to find a way to still use his system, but I'm afraid it won't work. Any help would be greatly appreciated!

Upvotes: -1

Views: 723

Answers (1)

Harshdeep Singh
Harshdeep Singh

Reputation: 315

Possible Solution

I won't be writing the code for this as it's too implementation-specific, but here's some checklist pseudo-code.

Use the following to compute relative positions between two players:

  1. Compare first by laps.
  2. If same laps, compare by checkpoints.
  3. If same checkpoints, compare using a distance function to next checkpoint. This function may be as simple as Euclidean distance, but I'd recommend whatever you're using for your AI pathfinding.

If you want absolute positions of all players, make an array, and sort it using laps, then breaking ties with checkpoints, and finally breaking ties with distance.

Even a hundred-entity race running this every frame shouldn't have any problems.

Upvotes: 1

Related Questions