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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by dail · Feb 05, 2015 at 12:50 PM · c#2dtransforminputjump

Input.GetButton not working

Hello guys. I would ask for your help to solve my problem. I have a cube that walks among an array of gameobjects and this works fine. But the function ' Input. GetButton ' or any other similar command does not work. Below is the code:

   public Transform[] pathNodes;
   public float movementSpeed = 0.5f;
   public bool continuouslyLoop = false;
   private float pathPosition = 0f;
   private int curNode = 0;
   
   void Update () {
       if (pathNodes != null)
       {
           pathPosition += Time.deltaTime * movementSpeed;
           if (pathPosition > 1f)
           {
               if (pathNodes.Length > curNode+2)
               {
                   pathPosition = 0f;
                   curNode += 1;
               }
               else
               {
                   if (continuouslyLoop) 
                   {
                       pathPosition = 0f;
                       curNode = 0;
                   }
               }
           }
           transform.position = Vector3.Lerp( pathNodes[curNode].position, pathNodes[curNode+1].position, pathPosition );
       }

       if (Input.GetButtonDown("Jump")) {
           Jump();
       }
 
   }
 

Comment
Add comment · Show 9
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 gjf · Feb 05, 2015 at 12:39 PM 0
Share

in the Input$$anonymous$$anager, is "Jump" defined as a button?

avatar image dail · Feb 05, 2015 at 12:46 PM 0
Share

Yes, it's defined

avatar image reihe0 · Feb 05, 2015 at 01:11 PM 0
Share

$$anonymous$$aybe the input is prevented by some gui?

avatar image sniper43 · Feb 05, 2015 at 01:34 PM 0
Share

Can we get the jump function? And are you sure the "Jump" axis has the appropraite buttons?

avatar image dail · Feb 05, 2015 at 01:59 PM 0
Share
 rigidbody2D.AddForce(Vector3.up * jumpSpeed * Time.deltaTime);
 
 
 I have also used and did not work in the console
 
 if (Input.GetButtonDown("Jump")) {
            Debug.Log("Test");
        }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sniper43 · Feb 05, 2015 at 04:08 PM

 transform.position = Vector3.Lerp( pathNodes[curNode].position, pathNodes[curNode+1].position, pathPosition );

You're lerping the positions while trying to use AddForce to jump. You're lerping every frame, so the velocity doesn't really have time to throw the object into the air.

Remember that Rigidbodies run on a seperate loop and you generally don't want to adjust position when you have a rigidbody or addforce when you have a position. Use LookAt to make your object face then nodes then AddForce(transform.forward, floatForceAmount) or set velocity to propel it forward.

Do this in FixedUpdate()

Otherwise, adapt your node position so that you add a vertical vector to it that represents the current jump height.

Hope this helps.

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

7 People are following this question.

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

Related Questions

(C#) A better way to limit actions to once per button press? 2 Answers

GetButtonDown not always firing 1 Answer

Jump and run on a circle (2D) 0 Answers

Divide screen in half for two buttons 1 Answer

3D coyote time 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