- Home /
Double jump does not work why?
Here is the code that is giving me difficulties.
//Jump stuff
if (Input.GetKeyDown(KeyCode.Space))
{
if (isGrounded)
{
Jump();
}
else if (canDoubleJump)
{
DoubleJump();
}
}
Debug.Log(canDoubleJump);
private void Jump()
{
rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
canDoubleJump = true;
}
private void DoubleJump()
{
rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
rb.AddForce(moveDirection * jumpForce / 2, ForceMode.Impulse);
canDoubleJump = false;
}
I checked with the debug logs and when it is in the air canDoubleJump is true. But when I try to double jump in the middle of the air, nothing happens. The player just falls down as though DoubleJump() never occurs ever.
Is there something in this code that I am missing? Because by what I can see, canDoubleJump should be true when I expected it to be true. I don't understand
looks good on first glance. Did you put a debuglog in your doublejump function to make sure that it really does not get triggered? Since you apply 2 forces you might also just cancle each other out and just not see the result.
I put a debuglog in the function. The message doesn't appear when I try to double jump, so it looks like the function is never triggered for some reason.
Your answer
Follow this Question
Related Questions
I need help with a movement script 1 Answer
why will my jump animation only play on multi-jumps? 0 Answers
Keep Horizontal Momentum after Jump 2 Answers
Interpolate problem? Jump isn't smooth... 1 Answer
Jumping increases movement speed 1 Answer