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 jdog98 · Dec 02, 2014 at 04:52 PM · c#javascriptpositioncartutorial

Making a race car positioning system

My game is nearly complete, I even have ai cars. I just dont know how to make a car positioning system for the players. I mean like 1st 2nd 3rd..... Can somone explain how to do that? Im not asking for someone to just give me a script, I would prefer a tutorial of some type. As long as I understand whats happening in the script..... C# please, but java is also acceptable. I know theres somthing in the asset store you can buy(its expensive), but im looking to learn, not own.

Comment
Add comment · Show 4
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 nirharpaz · Dec 02, 2014 at 05:09 PM 0
Share

If i understand correctly, do you mean that you can position each car and it will be perfectly placed the moment you select it despite its size difference?

avatar image jdog98 nirharpaz · Dec 02, 2014 at 05:13 PM 0
Share

no, im looking for a way to calculate the distance of each car from the first car, organized in order from least to greatest.

avatar image jdog98 · Dec 02, 2014 at 07:43 PM 0
Share

Hmmm... can a trigger enter a trigger?

avatar image nirharpaz · Dec 02, 2014 at 08:23 PM 0
Share

trigger enter is triggers when 2 collider triggers "collide"

yea you start the checking upon trigger enter the matching function recieves a car and then toy trigger collide with other:Collider you do the checking with this other.

since trigger stay check happen every frame - means 30 times a sec or so, you do it in no time

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by bubzy · Dec 02, 2014 at 05:49 PM

make gameobject prefabs, give them the tags "firstPlace" "secondPlace" etc

when you instantiate the cars, search for the gameobjects and use their transform to position the car.

Comment
Add comment · Show 2 · 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 jdog98 · Dec 02, 2014 at 05:54 PM 0
Share

We are trying to figure out who's closest to the finish line while the race is happening

avatar image bubzy · Dec 02, 2014 at 09:32 PM 0
Share

yes, sorry i thought you meant on the starting grid

avatar image
1

Answer by Baste · Dec 02, 2014 at 05:57 PM

Here's one way I can think of:

1: Place checkpoints at regular intervals along the track. Put them in a ordered list of some sort, so you know their ordering.

2: Have each car know which checkpoint is the last one it passed. You can do this by distance checking, or by triggers, or something else that's clever.

3: Rank cars by which checkpoint they passed last. If two cars' last checkpoint is the same, rank them by their distance to the next checkpoint.

That should probably cover the basics. There's a lot of fine tuning to do, but that's depending on the game. Oh, and I think you'll need a checkpoint just before and just after every turn to make this work - otherwise the distance calculations will be weird.

Hope that helps!

Comment
Add comment · Show 2 · 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 NoseKills · Dec 02, 2014 at 06:16 PM 0
Share

@Baste 's approach is good.

In a Facebook racing game i was a programmer in, we used an advanced version of this. We had a level editor with track pieces to build with. Each track piece had a few "waypoints" built into the 3D model. When going to race, we dynamically parsed the list of waypoints from start to finish to get a list of nodes signifying a complete lap.

When racing, I would use (surprisingly) simple vector math in Update() to project the cars position onto the node/vector representation of the track. This way we could calculate the car's progress on the track "analogously", not just update it when it moves over a certain node/collider. It also gave us a pretty fool proof way of tracking whether the car cheated by taking a short cut or something.

If you are planning on having branching in the track or more freedom of movement in some other form, this approach might get very complicated quickly.

avatar image jdog98 · Dec 02, 2014 at 06:45 PM 0
Share

I'm thinking I might have an object look at the player, and the course progress is deter$$anonymous$$ed by that objects local rotation

avatar image
1

Answer by nirharpaz · Dec 02, 2014 at 07:24 PM

my idea would be then: give a rank to each car

int rank;

that is initialized at the start according to position. add a trigger collider / other proximity sensor to each car.

when 2 cars are in sensor (collider could be horizontal thin box, 90deg from the ground, creating horizontal cross with the road) OnTriggerStay - monitor their position who is 1st by angle (/ shape means 2nd in before, \ sape means 1st is before) OnTriggerExit - stop those calcs.

also, if box is thin enough and you dont need the updated rank every given sec you can just update when they leave trigger.

might be clumsy but it will give u an updated info in any given moment.

Comment
Add comment · 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
1

Answer by nnadiwisdom1 · Nov 08, 2020 at 12:13 AM

if you need a solution check this link https://youtu.be/eKFVTLO6-E4

Comment
Add comment · 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
0

Answer by kapyar · Feb 09, 2016 at 05:14 PM

Hey, you could try my plugin which can handle all math. Its really simple to use you must add only 2 prefabs to your scene https://www.assetstore.unity3d.com/en/#!/content/45698

Comment
Add comment · 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

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

31 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to set speed limit of car? 3 Answers

Car- can someone help me convert this to C#? 1 Answer

where can i find a series of video c# tutorials or javascript tutorials 3 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