Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kidshenlong · Mar 25, 2013 at 06:08 PM · positionarrayswaypointsracecheckpoints

Setting up player positions in a racing game

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.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Mar 25, 2013 at 06:13 PM 0
Share

Ummm, each player can't have a static int - that's shared by all players.

avatar image kidshenlong · Mar 25, 2013 at 06:27 PM 0
Share

EDIT: Completely misread your comment lol but thanks for the heads up. I've only got 1 racer atm so this will change lol!

avatar image Graham-Dunnett ♦♦ · Mar 25, 2013 at 08:26 PM 1
Share

What you propose in your edit to the questions makes sense to me. If ins$$anonymous$$d of the lap being 1000 units, it was, say 1200metres, then your int could actually measure how far in metres the player has travelled. Or, use floats, and have one lap as 1 unit, hence three quarters of the way around lap 5 would be 4.75. Either way you're measuring distance, either in metres or laps. Then, as you say, you have an associative array with keys being the player number (player1, player2, etc) and the values being the distance they have travelled. Sort by key to get a list sorted by player, and by key to get a current ranking.

avatar image kidshenlong · Mar 26, 2013 at 12:16 AM 0
Share

Right, 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 $$anonymous$$d posting an example? It'd really help clear things up.

avatar image Graham-Dunnett ♦♦ · Mar 29, 2013 at 05:47 AM 0
Share

Use a Dictionary.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kidshenlong · Mar 29, 2013 at 07:25 PM

So after scouring the net and getting help from a few different places I've come to a resolution.

Lists.

I put all the player objects into a list and then by using linq I then order the list by accessing the progress int which is the value that represents the player's progress through the course.

 myList = myList.OrderByDescending(x => x.GetComponent<CarCheckpoint>().progress).ToList();

Thanks for all your help...

I do still have one issue though. When the player goes through a checkpoint it updates the progress integer. This is ineffective though as the player's positions are only updated when crossing through a checkpoint.

As I discussed above I do have bit of code that measures distance between each checkpoint. This is then turned into a percentage. So if a player is half way to the next percentage it'll be 50% obviously...

I'm not sure how to word this but I'm hoping to add the percentage as an integer onto the progress int but instead of constantly incrementing this number only to add the difference on each time.

just to clarifying:

If player one's position is the 50% between checkpoint 2 and 3. The progress should be at 250, but when they get to 55% the progress integer should be at 255. So I'm looking to just add on the difference rather than adding 50 then 55 and ending up with 305 or some other ridiculous number.

Found it difficult to word that so please reach out if this isn't making any sense lol

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image abdulthegamer · May 21, 2014 at 08:05 PM 0
Share

Hi kidshenong,

Will you please share the script to calculate the ranking of car in racing game. Any help will be appreciated. Regards.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add progress bar showing player movement from start to finish line in 3d game ?, 1 Answer

How to make a Race Standing / Position Indicator 0 Answers

Camera rotation around player while following. 6 Answers

Racer positioning system and race end 0 Answers

players positions when race ends. 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges