- Home /
Character Jumping Not Working Sometimes
Hello, I have a 2D sidescroller game where the player can make the character jump by pressing the space bar. However, sometimes the character does not jump when I press space.
So, I have this function called PlayerMovement () which is being called every frame through Update. Simple.
Then, in the PlayerMovement function, I have a variable and an if statement:
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
if (Input.GetButtonDown("Jump")) { moveDirection.y = playerJumpSpeed; audio.clip = jumpSound; audio.Play(); } }
playerJumpSpeed
is a variable which never changes.
moveDirection
is a Vector2 variable which is used to move the controller with:
controller.Move(moveDirection * Time.deltaTime);
Anybody know what the problem could be?
Sorry...can't get my code formatting to work correctly
Answer by create3dgames · Sep 11, 2013 at 07:06 PM
Okay, I figured it out. Now I'm using Input.GetButton
instead of Input.GetButtonDown
. Seems to work!
i would like to give 1000+ thumbs up for this -> i was looking so long for this error and finally this old entry helped me ^^
$$anonymous$$y jumps became responsive after changing from FixedUpdate() back to Update() method. $$anonymous$$y run state was corrected after setting an else condition after checking if the run key was held down, ins$$anonymous$$d of just making a statement that walk speed should follow a check for the run-button.
Your answer
Follow this Question
Related Questions
Let Character Controller jump. 0 Answers
Let Character Controller jump. 1 Answer
(CharacterController) Jumping from other script 0 Answers
Jump and move (CharacterController.velocity) C# 0 Answers
Jumping not always work 2 Answers