Forum begins after the advertisement:
-
::I implemented the jump stuff and everything works well but there is this one problem. When I don’t hold down the jump button and instead just push and release very quickly, character makes a full jump instead of making a very short one. I think the editor doesn’t update fast enough so it doesn’t see that I released my jump button and it doesn’t set the vertical velocity to 0. How can I solve this issue?
::Hi alp Erkan,
You will have to add a new line of code in your jumping script to check if 1) you are jumping and 2) the jump button is not being held down, and then set the vertical velocity to zero.
EDIT: See below for the code.
::Terence,
Can you please provide the code for fixing this problem ? Especially setting the vertical velocity to zero.
::Hi burbza,
I haven’t tested this, but you can try this and see if it works. I’ve highlighted the change to the code below:
void Jump()
{
if(!Input.GetButtonUp("Jump") && rb.velocity.y > 0)
{
rb.velocity = new Vector2(rb.velocity.x, 0);
pState.jumping = false;
}
if (!pState.jumping)
{
if (jumpBufferCounter > 0 && coyoteTimeCounter > 0)
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce);
pState.jumping = true;
}
else if(!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown("Jump"))
{
pState.jumping = true;
airJumpCounter++;
rb.velocity = new Vector3(rb.velocity.x, jumpForce);
}
}
anim.SetBool("Jumping", !Grounded());
}
Update: I missed the !
in the code highlighted in green above in my earlier edit of the post.
::Now the player can’t jump at all when i’m holding the jumping button. I can do only very small jumps and only if i press the jump button very fast.
::Hi burbza, I updated the code above (in the green highlight). Let me know if the new code works for you.
Advertisement below: