Question by
Alex_lemes · Feb 21, 2018 at 12:46 PM ·
jumpingdouble jump
Player jumping issue
Hello,
I've got a really frustrating issue with my player jumping. I'm trying to do double jump & atm I have it constantly double jumping fine, but the player can double jump when they aren't supposed to, here is the code:
{
MovementFunction();
}
void MovementFunction()
{
float h = Input.GetAxis(horizontalattribiute) * speed * Time.deltaTime;
float v = Input.GetAxis(verticalattribute) * speed * Time.deltaTime;
if (IsGrounded())
{
currentJumpAmounts = jumpAmounts;
}
movement = new Vector3(h, 0, v);
if (rb1.velocity.magnitude > maxSpeed)
{
rb1.velocity = rb1.velocity.normalized * maxSpeed;
}
rb1.AddForce(movement);
if (Input.GetKeyDown(KeyCode.Space) && currentJumpAmounts > 0)
{
currentJumpAmounts--;
rb1.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
Debug.Log("IsGrounded = " + IsGrounded());
}
}
private bool IsGrounded()
{
return Physics.CheckCapsule(col1.bounds.center, new Vector3(col1.bounds.center.x, col1.bounds.min.y, col1.bounds.center.z), col1.radius * 0.9f, groundLayers);
}
Now if I set jumpamounts = 1 - the player can double jump all the time when they should only jump 1 time. If I set it to 0, they cannot jump at all.
I've debugged it down to find out that the grounded function is only false AFTER the first jump, it's not being called & checked properly after the 1st jump.
I've tried everything and just cannot seem to find the solution.
Thanks for any help!
Comment
Your answer
Follow this Question
Related Questions
2d Platformer double jump wont work 2 Answers
Player not double jumping. 0 Answers
player not able to double jump 0 Answers