Hi everyone,
I’ve been trying to setup player positions in game. Been all over the forums and managed to get this far but just need a little help with the last step.
I’ve set up a race course that has a series of checkpoints. These checkpoints are just to track the players position through the track and make sure they’re at the right point and stop them incrementing the lap counter by just going over the line continuously.
So every racer has
public static int currentCheckpoint = 0;
public static int currentLap = 0;
The checkpoints are triggers that increment the currentCheckpoint int and when a player successfully goes through the every waypoint currentCheckpoint is set to 0 and currentLap is then incremented.
My issue is now setting up something that’ll allow me to work out the position of each player.
Just needed a little assistance in how I should sort this information. I was thinking an array? That would just constantly be sorted depending on the player’s checkpoint and lap count.
I’ve managed to set up a system that stores the distance of each racer to the next checkpoint they are due to clear so this would be another variable I’d have to take into account.
I’m pretty sure the logic behind the code would be putting each of these variables into an array and then Sorting the Lap array to find out which lap players are in and then sorting the current checkpoint array and then finally the distance to waypoint array.
Any advice on this would be greatly appreciated.
Thanks!
EDIT: I was thinking about turning the player’s position information into one int. So let’s say there were 10 checkpoints. A int higher than a 1000 would indicate them being on the second lap and so on. And I was thinking about converting the distance into a percentage so it would always be out of a 100 and add up to 1000…
Bad idea?
EDIT 2:
So I’ve managed to set up some arrays which keep track of the lap of the player and of the checkpoint they’re on. But in terms of ordering them I’m a little lost. I could sort them but because the array’s only hold the checkpoints and laps as separate integers there’s no index to reference which number belongs to which player once they’ve been sorted. I was hoping to make them multidimensional so I could have the actually player’s object as the index to relate to the lap and checkpoint to sort them. The problem I’m not too sure how to make a multidimensional array with different types… Can arrays even do this or would I need a list or something else?
Any input or direction here would be much appreciated.
Ummm, each player can't have a static int - that's shared by all players.
– whydoidoitEDIT: Completely misread your comment lol but thanks for the heads up. I've only got 1 racer atm so this will change lol!
– kidshenlongRight, this is going horribly. I've managed to set up arrays holding the information separately but like you said I'm going to need a key/index so it's going to have to be multidimensional array which I'm not too sure how to set up. It'd mixed type array I think so I could put the player's gameobject in, or maybe I could just make a unique key and do it that way. From there it'd just be sorting and displaying the information. I've tried Google but the examples aren't too clear. Would anyone mind posting an example? It'd really help clear things up.
– kidshenlongUse a [Dictionary][1]. [1]: http://msdn.microsoft.com/en-us/library/x525za90.aspx
– Graham-DunnettI've come up with a solution please view the answer below as I'm a little stuck on the final bit and would appreciate any assistance!
– kidshenlong