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 /
This question was closed Feb 11, 2015 at 08:54 PM by Abacab for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Abacab · Feb 11, 2015 at 08:32 PM · c#buttoncar

Car game Reverse Button

Hello!

How do I create a button that, when pressed, makes the car go backwards?

My gas button works like this:

 public void Gas ()
         {
                 motorInputTouch = 1;
                 gasOn = true;
                 Debug.Log ("Gas");
 
                 wheelBR.brakeTorque = 0;
                 wheelBL.brakeTorque = 0;
         
                 // First gear
                 if (currentSpeed <= 150 && currentSpeed > -maxReverseSpeed && !braked) {
                         wheelBR.motorTorque = OneTorque * motorInputTouch;
                         wheelBL.motorTorque = OneTorque * motorInputTouch;
                 }
                 // Second gear
                 else if (currentSpeed <= 300 && currentSpeed > 150 && !braked) {
                         wheelBR.motorTorque = TwoTorque * motorInputTouch;
                         wheelBL.motorTorque = TwoTorque * motorInputTouch;
                 }
         
                 // Third gear
                 else if (currentSpeed <= 450 && currentSpeed > 300 && !braked) {
                         wheelBR.motorTorque = ThreeTorque * motorInputTouch;
                         wheelBL.motorTorque = ThreeTorque * motorInputTouch;
                 } 
         
                 // Fourth gear
                 else if (currentSpeed > 450 && currentSpeed <= topSpeed && !braked) {
                         wheelBR.motorTorque = FourTorque * motorInputTouch;
                         wheelBL.motorTorque = FourTorque * motorInputTouch;
                 } else {
                         wheelBR.motorTorque = 0;
                         wheelBL.motorTorque = 0;
                 }
         }
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Feb 11, 2015 at 08:45 PM

I assume you call Gas() by pressing a button? You could create a second method called Backwards() getting called when you press another button.

If you want all that in your Gas() method, maybe you could wrap all your gear checks into a if (forward) boolean check. Then there's the else to do back traveling. Toggle that boolean upon pressing the button.

Comment
Add comment · Show 4 · 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 Abacab · Feb 11, 2015 at 08:47 PM 0
Share

No I'd like to do a different button and call Reverse(), but I don't know how I can make the car go backwards.

Is it something like:

 wheelBR.motorTorque = OneTorque * -motorInputTouch;
 wheelBL.motorTorque = OneTorque * -motorInputTouch;
avatar image hexagonius · Feb 11, 2015 at 08:49 PM 0
Share

Why wouldn't you try that? ;)

avatar image Abacab · Feb 11, 2015 at 08:52 PM 0
Share

Nothing happens. :(

avatar image Abacab · Feb 11, 2015 at 08:54 PM 0
Share

Never$$anonymous$$d forgot to add motorInputTouch = 1; !!!

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Reverse Button problem 0 Answers

Laggy Camera 2 Answers

Trouble detecting button release with Input.GetButtonUp() 1 Answer


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