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 kikoncuo · Jul 24, 2014 at 09:09 PM · getmousebuttondowngetmousebutton

Irregular jumping

Hi I'm trying to get my gameobject to jump by adding a force only when it touches the ground which works fine when I use Input.GetButtonDown but when I use Input.GetButton the jump is irregular (Randomly it seems), I thought maybe force was applying more than once if I keep the button pressed, but I if I put a bool to control that the same thing happens, any ideas?

Here is my code:

 void Update () {
 
         if (Cubo!=null){
         transform.Translate(Vector3.right*moveright);
             if (suelo & Input.GetButton("Fire1")
 & fuerza){ 
                 Cubo.transform.rigidbody.AddForce(transform.up*jump*10*(Time.fixedDeltaTime));
                 fuerza=false;
 
         }
         else{
                 Cubo.transform.rigidbody.AddForce(transform.up*(-jump*.85f)*Time.fixedDeltaTime);
                 fuerza=true;
 
         }
     }
     }
 
     void OnTriggerEnter (Collider other) {
         suelo=true;
     }
 
     void OnTriggerExit (Collider other) {
         suelo=false;
     }
 

Here is a short video demo of what happens

http://youtu.be/-mR84CIUKXs

In the video I show first what happens with Input.GetButtonDown, then I change the code to Input.GetButton to show the difference and I click as fast as I can to make the same effect

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Stormizin · Jul 24, 2014 at 09:15 PM

Input.GetButton: Returns true while the virtual button identified by buttonName is held down.

Input.GetButtonDown: Returns true during the frame the user pressed down the virtual button identified by buttonName.

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 kikoncuo · Jul 24, 2014 at 10:56 PM 0
Share

I know that but I restricted the Input.GetButton to only act once when the game object touches the ground and still does the same, I also tried to use forcetype.impulse but it throws the object flying in the air

avatar image Stormizin · Jul 25, 2014 at 02:13 PM 0
Share

Did this restric really work?

avatar image kikoncuo · Jul 26, 2014 at 08:11 PM 0
Share

I've tried this now and it doesn't, I may have not tested it correctly my bad do you think this restraint would work? Is so how would you implement this? Thank you

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make an object appear only when I click and not when I drag 2 Answers

C# GetMouseButtonUP on specific object ??? 0 Answers

Raycast repeats multiple times 2 Answers

Input.mousePosition changing to (0,0) after GetMouseButtonUp 1 Answer

Mac menu bar interfering with click events 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