- Home /
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);
Answer by smallbit · Mar 11, 2015 at 09:05 AM
try
Input.GetButtonDown()
instead of
Input.GetButton
With GetButton action will be executed each frame while you hold the button. With GetButtonDown the action will go only once. also normally you dont need to add force for the player to land, he should go back to ground with gravity.
Your answer
Follow this Question
Related Questions
Max height jump 2 Answers
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