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 tommy1235 · May 05, 2013 at 11:26 AM · inputjoystick

Joystick 10th axis code problem

i have an interesting problem, this piece of code is inside the Update function and everything works fine besides "Input.GetAxis("Fire1Jostick") > 0.5" when i pull the trigger the second axis is repeatedly fired causing the player to shoot 6 pistol rounds instantly

     if(Input.GetButtonDown("Fire1") || Input.GetAxis("Fire1Jostick") > 0.5){
         if(Trigger == true){
             Shoot();
             Trigger = false;
         }else{
             Trigger = true;
         }
     }


and this problem has not happened with the button so i know the code works(for a button)

BTW the Fire1Jostick is Axis 10(for xbox360 controller)

Thanks

Comment
Add comment · Show 1
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 tommy1235 · May 07, 2013 at 07:34 AM 0
Share

so nobody has ever had this problem?

1 Reply

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

Answer by s_guy · Aug 12, 2013 at 09:17 PM

The Update function is called every frame and Input.GetButtonDown() is only true for the one frame that the button is pressed. (See http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html) So, your condition to fire is true only once when using that button and you get one call to Shoot().

On the other hand, Input.GetAxis() reports the status of the axis every frame. Since you won't likely have the trigger pulled for only one frame, your condition to fire is true for several frames. The same sort of thing will happen when you use Input.GetButton(), which reports true not just for the frame it's pressed, but for every frame while it's held. So, you get many calls to Shoot().

They typical solution for a single shot with this kind of input, is to save a bool for if a shot was fired and only reset this once the button up condition is met.

Here is an answer with a code example http://answers.unity3d.com/questions/376587/how-to-treat-inputgetaxis-as-inputgetbuttondown.html

If you wanted auto-fire, you could watch Time.time to see if enough time has passed since the last bullet was shot. Then that will be an additional condition for shooting that bullet.

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Main Menu: Is it better to subdivide it into different scenes? 1 Answer

How can I play with one joystick? 0 Answers

Combining first person contoller and dual touchpads from standard assets 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