Get 25% off your next order from the Unity Asset Store: YW86GYBU8S.
Forum begins after the advertisement:
[Part 2] Jump issue
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 2] Jump issue
- This topic has 5 replies, 3 voices, and was last updated 2 years ago by
Terence.
-
AuthorPosts
-
October 12, 2023 at 2:35 am #12070::
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?
October 12, 2023 at 1:26 pm #12071::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.
October 28, 2023 at 11:41 pm #12124::Terence,
Can you please provide the code for fixing this problem ? Especially setting the vertical velocity to zero.
October 29, 2023 at 12:12 pm #12125::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.October 30, 2023 at 1:50 am #12133::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.
October 30, 2023 at 4:24 pm #12138 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below:
Get 25% off your next order from the Unity Asset Store: YW86GYBU8S.