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 falconer · Feb 06, 2013 at 06:05 AM · stopcar game

How to stop the car after the finish line?

hello, I'm working on a racing car game, I'm not getting how to stop the car after the car reaches the finish line. I've managed to stop the timer but I couldn't write a code to stop the car. Kindly help!!!1

Comment
Add comment · Show 2
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 robertbu · Feb 06, 2013 at 06:37 AM 0
Share

Is your problem writing the code to make the code stop or is your problem communicating that the car has reached the goal to the car?

avatar image falconer · Feb 06, 2013 at 10:09 AM 0
Share

stopping the car bro

2 Replies

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

Answer by CodeMasterMike · Feb 06, 2013 at 06:15 AM

If you mean you want to stop the user input (acceleration, breaking, steering etc) from making the car move, then you need to put some kind of check to make sure that the player has reached the finish line:

 if(PlayerHasReachedGoal == false)
 {
  // Check the player car input here...
 }

If you mean that that the car should stop instantly without slowing down or using the brakes, then you should probably set the motortorque manually for all wheels to 0 every update:

 void Update()
 {
  if(PlayerHasReachedGoal == true)
  {
   Wheel1.motorTorque = 0;
   Wheel2.motorTorque = 0;
   Wheel3.motorTorque = 0;
   Wheel4.motorTorque = 0;
  }
 }

Worth mentioning is that I haven't used the car physics, so this above may be wrong, but it maybe gives you some idea how to stop the car without user input.

Good luck!

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 falconer · Feb 06, 2013 at 11:49 AM 0
Share

I prefer the 1s one. I tried to call the GetInput function using the if statement but it didnt work :( here's the code i used

if(myWC.GetGroundHit(hit)) { if(hit.collider.gameObject.tag == "finish") { GetInput(); }

avatar image
0

Answer by falconer · Feb 06, 2013 at 11:53 AM

Thank you for that reply, I prefer the first one. But i'm not getting how to do it. Below is the code I've used to stop the timer after the car reaches the finish line. If anybody could add the instructions to stop the car would be very helpful.

 var pastTime : float;
 var myWC : WheelCollider;
 private var isFinished : boolean = false;
 var guiTime : GUIText;
 
 function Update () {
 var hit : WheelHit;
 
 if(myWC.GetGroundHit(hit)) {
  if(hit.collider.gameObject.tag == "finish")  {
   isFinished = true;
   
  }
 
 if(!isFinished) {
  pastTime += Time.deltaTime;
 }
 
 guiTime.text = pastTime.ToString();
 }
 }
Comment
Add comment · Show 14 · 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 CodeMasterMike · Feb 06, 2013 at 11:54 AM 0
Share

Where do you have your input code?

avatar image falconer · Feb 06, 2013 at 12:10 PM 0
Share

I named this as Timer and the input code is present in Car javascript

avatar image falconer · Feb 06, 2013 at 12:11 PM 0
Share

I'm using the unity demo car tutor as reference one

avatar image CodeMasterMike · Feb 06, 2013 at 12:14 PM 0
Share

Ok, well, wherever the input code is, you need to add the "Is the player finished?" check, and if the player is not finished, then you proceed to check the input functions. If the player is finished, then you do not proceed to check the input functions.

avatar image falconer · Feb 06, 2013 at 03:25 PM 1
Share

You are great!!! one thing you missed was to make throttle=0...... Nevertheless you are my saviour :) Thank you so much..

Show more comments

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

10 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

Related Questions

Nitro bar setup 1 Answer

RotateAround() using local rotation axes 2 Answers

How to make a pause function? 3 Answers

Wheel Collider General Friction 1 Answer

Stop object collision 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