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 CC Inc · Mar 13, 2012 at 04:20 PM · cartutorialstop

Unity Car tutorial Brake

Hi,

I am using the car and some scripts from the Unity3d car tutorial, and when I accelerate then release the button, the car keeps on going, and even after I brake it, it rolls. How can I set it to decelerate faster,and to stay stopped?

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 CC Inc · Mar 16, 2012 at 09:09 PM 0
Share

Does anyone have any suggestions?

avatar image hijinxbassist · Mar 16, 2012 at 09:25 PM 0
Share

Im not familiar with this tutorial...so im not sure how acc/dec are handled(nor have i ever made a car game). Im sure there is a var in the script that handles the cars movement named deceleration(or something of the sorts) that you can tweak to your liking. But i cant really say what it is without digging through the scipts on the tutorial.

1 Reply

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

Answer by hijinxbassist · Mar 17, 2012 at 12:36 AM

Ok, so its pretty complex as expected. Found the line where the braking takes place. Line 527 of the car script(java).

 rigidbody.AddForce(transform.forward * Time.deltaTime * (throttleForce + brakeForce));

Here are the 2 vars that handle the acc/dec of the car.

NOTE: If you are using this script w/o changes, acc/dec will be at the same rate(the posted line handles both acc/dec). So if you are trying to stop quicker than you accelerate, it might be a good idea to make an add on script that applies additional stopping force.

Theres a few ways to add extra brake force. You could add a boolean to the car script called braking and make this true when the throttle force is negative.

 public var braking:boolean;
 
 function Update()
 {
     if(throttleForce<0)braking=true;
     else braking=false;
 }

then from the new script

 public var braking:boolean;
 public var extraBrakeForce:int;
 
 function FixedUpdate()
 {
     braking=transform.GetComponent(Car).braking;
     if(braking)rigidbody.AddForce(transform.forward*Time.deltaTime*(-extraBrakeForce));
 }

Not tested, but should work. Dont forget to set your extra brake force from inspector. Let me know if it works out ok.

Comment
Add comment · Show 3 · 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 CC Inc · Mar 17, 2012 at 02:05 PM 0
Share

That works when I am braking, but not when the car is just rolling. Also, I had to change throttleforce to throttle

avatar image hijinxbassist · Mar 17, 2012 at 09:11 PM 1
Share

Right right, since it is extra brake force. You could add some more force when braking isnt true. like...

 public var braking:boolean;
 public var extraBrakeForce:int;
 public var extraDrag:int;
 
 function FixedUpdate()
 {
     braking=transform.GetComponent(Car).braking;
     if(braking)rigidbody.AddForce(transform.forward*Time.deltaTime*(-extraBrakeForce));
     else if(!Input.GetAxis("Vertical")&&rigidbody.velocity.magnitude>0)
     {
         rigidbody.AddForce(transform.forward*Time.deltaTime*(-extraDrag));
     }
 }

or use the same var ins$$anonymous$$d and divide it by an amount...unless you want the full extra brake force applied as drag. Basically what the new line says is...

If braking is false (else), if you are not pushing the vertical button (!Input.GetAxis("Vertical")), and if the car is actually moving still (rigidbody.velocity.magnitude>0).

I hope this explanation will help you understand how i accomplished this.

avatar image mak · May 27, 2012 at 10:38 AM 0
Share

Assets/Scripts/JavaScripts/Car.js(539,10): BCE0044: expecting (, found 'FixedUpdate'.

Im trying to get this to work in Android ,any idea why I get this error please ? :)

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

6 People are following this question.

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

Related Questions

Car Tutorial Issue .......... 5 Answers

When I spawn the car, I can not hear the sound. Why 0 Answers

How do I download the new unity 5 car tutor? 1 Answer

Unity Car Tutorial Error 0 Answers

Making a race car positioning system 5 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