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 SouzaDev · Feb 04, 2015 at 04:40 PM · c#2dcharacterjump

Max height jump

Hello everyone, I have a problem in my code and would like your help. The problem is that when the jump button is pressed, the character jumps repeatedly, I want him to jump only once even if the resume button pressed. I've tried a few things but he didn't jump completely. And I would help so that my character has a maximum height of jump and then return to the floor

 if (Input.GetButton("Jump")){
   
   rigidbody.AddForce(Vector3.up * jumpHeight,ForceMode.Impulse);
   }
   else
   rigidbody.AddForce(-Vector3.up * jumpDown,ForceMode.Impulse);
Comment
Add comment · Show 4
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 Pendantic · Mar 10, 2015 at 04:25 PM 0
Share

http://answers.unity3d.com/questions/919654/how-do-you-make-a-2d-rigidbody-jump-once-in-unity.html would be a good idea to stop jumping while not on the ground. You're also using get button which is true aslong as you hold the button down you most likely want GetButtonDown as it is only true the first frame.

avatar image Kumo-Kairo · Mar 10, 2015 at 04:26 PM 0
Share

You should only allow jumping when your character is standing on the floor. Also, use GetButtonDown so it will be easier to add double jumps later

avatar image Neamtzu · Mar 10, 2015 at 04:29 PM 0
Share

Try this

 (Input.Get$$anonymous$$eyDown("space")

Ins$$anonymous$$d of

 if (Input.GetButton("Jump"))




avatar image SouzaDev · Mar 10, 2015 at 04:52 PM 0
Share

I appreciate your answer. But I'm using GetButton ("Jump") because my character can jump with variable height and GetButtonDown wouldn't work well

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by d2 · Mar 10, 2015 at 04:44 PM

instead of Input.GetButton("Jump") use Input.GetKeyDown("Jump") or Input.GetKeyUp("Jump")

Comment
Add comment · Show 2 · 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 SouzaDev · Mar 10, 2015 at 04:56 PM 0
Share

If I use GetButtonDown the character gives only a tiny jump. I want to make the character jump with variable height, but with a height limit

avatar image d2 · Mar 10, 2015 at 05:14 PM 0
Share

try something like this:

 using UnityEngine;
 using System.Collections;
 
 public class Answers : $$anonymous$$onoBehaviour {
 
     public Rigidbody rigidbody;
     public float variableForce;
     public float jumpLimit;
 
     void FixedUpdate () {
         if (Input.GetButton("Jump")){
             rigidbody.AddForce(Vector3.up * variableForce,Force$$anonymous$$ode.Impulse);
         }
         else{
             rigidbody.AddForce(-Vector3.up * variableForce,Force$$anonymous$$ode.Impulse);
         }
         if(transform.position.y >= jumpLimit)
             rigidbody.velocity = Vector3.zero;
 
     }
 }
avatar image
0

Answer by AndrewToth · Mar 10, 2015 at 07:13 PM

You can try this

 if(Input.GetButtonDown("Jump"))
 {
    //do awesome stuff
 }
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

Max height jump 1 Answer

Jump & Animation Script 2D 0 Answers

Android 2D Character Controller 2 Answers

Character doesn't jump repeatedly 1 Answer

GetButtonDown not always firing 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