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 Ketwuns · Aug 20, 2013 at 02:53 AM · triggercaraccelerationgetaxis

Car acceleration using Xbox 360 triggers?

After looking at these links

http://wiki.unity3d.com/index.php?title=Xbox360Controller http://docs.unity3d.com/Documentation/ScriptReference/KeyCode.html

I noticed there is a direct way to enable those triggers on a 360 controller, or anything of similar nature. They are Six Axis or something for Right Trigger, and Fifth Axis for Left Trigger...on the Mac. Regardless, on Windows, they mix up the "Nth Axis" inputs, so Windows and Mac are different.

But I just need to know how do you call these here because it tells me error CS0029: Cannot implicitly convert type `float' to bool' ? Lines highlighted down below in bold.

Let's say it was this script:

   bool accelKey = Input.GetKey (KeyCode.UpArrow);
         float accelKey2 = Input.GetAxis ("6th axis (Joysticks)");
         bool brakeKey = Input.GetKey (KeyCode.DownArrow);
         float brakeKey2 = Input.GetAxis ("5th axis (Joysticks)");
         
         if (drivetrain.automatic && drivetrain.gear == 0)
         {
             accelKey = Input.GetKey (KeyCode.DownArrow);
             accelKey2 = Input.GetAxis("5th axis (Joysticks)");
             brakeKey = Input.GetKey (KeyCode.UpArrow);
             brakeKey2 = Input.GetAxis("6th axis (Joysticks)");
         }
         
         if (Input.GetKey (KeyCode.LeftShift))
         {
             throttle += Time.deltaTime / throttleTime;
             throttleInput += Time.deltaTime / throttleTime;
         }
         else if (accelKey)
         {
             if (drivetrain.slipRatio < 0.10f)
                 throttle += Time.deltaTime / throttleTime;
             else if (!tractionControl)
                 throttle += Time.deltaTime / throttleTimeTraction;
             else
                 throttle -= Time.deltaTime / throttleReleaseTime;
 
             if (throttleInput < 0)
                 throttleInput = 0;
             throttleInput += Time.deltaTime / throttleTime;
             brake = 0;
         }
         
         **else if (accelKey2)**
         {
             if (drivetrain.slipRatio < 0.10f)
                 throttle += Time.deltaTime / throttleTime;
             else if (!tractionControl)
                 throttle += Time.deltaTime / throttleTimeTraction;
             else
                 throttle -= Time.deltaTime / throttleReleaseTime;
 
             if (throttleInput < 0)
                 throttleInput = 0;
             throttleInput += Time.deltaTime / throttleTime;
             brake = 0;
         }
         
         else 
         {
             if (drivetrain.slipRatio < 0.2f)
                 throttle -= Time.deltaTime / throttleReleaseTime;
             else
                 throttle -= Time.deltaTime / throttleReleaseTimeTraction;
         }
         throttle = Mathf.Clamp01 (throttle);
 
         if (brakeKey)
         {
             if (drivetrain.slipRatio < 0.2f)
                 brake += Time.deltaTime / throttleTime;
             else
                 brake += Time.deltaTime / throttleTimeTraction;
             throttle = 0;
             throttleInput -= Time.deltaTime / throttleTime;
         }
         
         
         **if (brakeKey2)**
         {
             if (drivetrain.slipRatio < 0.2f)
                 brake += Time.deltaTime / throttleTime;
             else
                 brake += Time.deltaTime / throttleTimeTraction;
             throttle = 0;
             throttleInput -= Time.deltaTime / throttleTime;
         }
         
         else 
         {
             if (drivetrain.slipRatio < 0.2f)
                 brake -= Time.deltaTime / throttleReleaseTime;
             else
                 brake -= Time.deltaTime / throttleReleaseTimeTraction;
         }
         brake = Mathf.Clamp01 (brake);
         throttleInput = Mathf.Clamp (throttleInput, -1, 1);
                 
         // Handbrake
         handbrake = Mathf.Clamp01 ( handbrake + (Input.GetKey (KeyCode.Space)? Time.deltaTime: -Time.deltaTime) );
         
         // Gear shifting
         float shiftThrottleFactor = Mathf.Clamp01((Time.time - lastShiftTime)/shiftSpeed);
         drivetrain.throttle = throttle * shiftThrottleFactor;
         drivetrain.throttleInput = throttleInput;
         
         if(Input.GetKeyDown(KeyCode.R))
         {
             lastShiftTime = Time.time;
             drivetrain.ShiftUp ();
         }
         if(Input.GetKeyDown(KeyCode.F))
         {
             lastShiftTime = Time.time;
             drivetrain.ShiftDown ();
         }
 
         // Apply inputs
         foreach(Wheel w in wheels)
         {
             w.brake = brake;
             w.handbrake = handbrake;
             w.steering = steering;
         }
     }


Comment
Add comment · Show 5
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 Benproductions1 · Aug 20, 2013 at 03:02 AM 0
Share

$$anonymous$$ind posting what line the error is on?

avatar image Ketwuns · Aug 20, 2013 at 09:03 AM 0
Share

Check the stars man. Sorry they weren't formatted to bold properly.

avatar image Benproductions1 · Aug 20, 2013 at 09:07 AM 0
Share

@$$anonymous$$etwuns The standard way of presenting the lines are by just giving the line number. Formatting them in some way makes them harder to find and easier to miss.

Also note that in a code section you can't change formatting for obvious reasons :)

avatar image Ketwuns · Aug 20, 2013 at 05:58 PM 0
Share

Thank you...now..do you have an idea?

avatar image Benproductions1 · Aug 25, 2013 at 01:17 AM 0
Share

If I answered your question, please accept my answer :)

1 Reply

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

Answer by Benproductions1 · Aug 21, 2013 at 01:58 AM

Hello,

If we take a look at if statements, we can always express:

 if (condition)

to be the same thing as

 if (condition == True)

Going by this example, lets take a look at your code:
Looking at the lines with the error, we can see that you are checking:

 if (brakeKey2)

Which is (according to our previous definition) the same as

 if (brakeKey2 == True)

If we read the error, it looks like you are trying to convert a float type object to a bool type object (which you can't do).
So we take a look at the definition for brakeKey2 (as it's the only variable on that line):

 float brakeKey2 = Input.GetAxis(/*etc*/)

It is, as expected, a floating point variable.
The simple fact remains, is that you are trying to do something like 8.65 == True. How do you compare a float and a bool?
You can't.

What you need to do is write an expression that evaluates into a bool.
For instance:

 brakeKey2 == 0.0f

or

 brakeKey2 < 0.1 && brakeKey2 > -0.1

of maybe?

 !float.isNull(brakeKey2)

Now your if statement is getting a boolean value and not a float.

Hope this helps, :)
Benproductions1

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

16 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

Related Questions

Car's Acceleration is stuck 1 Answer

Car control with WASD keys or arrow keys 2 Answers

Unity car tutorial speed boost 1 Answer

Approach for forcing player movement 0 Answers

Below script is a car controller and i want the car to boost when hit a trigger object. Still new with unity T^ T 0 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