I have a problem with jump in my current project.
The good: Character jumps when button is pressed.
Character has a controllable height up to a certain limit with a minimum for input.
The bad: If the player holds down the button and approaches a ledge, they will jump automatically. Which might be neat for debugging and making sure platforms are a certain distance away but is not ideal from a game standpoint.
Included is the code and a video. The first part of the code is just to play the jump animation if the player isn’t climbing or grounded. So jumping or falling. The rest is the actual code and I know the issue must lie within the GetButton area, I just have no clue how to make it work from this point.
`void FixedUpdate()
{
if (!myFeet.IsTouchingLayers(LayerMask.GetMask(“Climbing”, “Ground”)))
{
myAnimator.SetBool(“isJumping”, true);
}
else
{
myAnimator.SetBool("isJumping", false);
}
if (CrossPlatformInputManager.GetButtonDown("Jump"))
{
if (grounded && (stoppedJumping=true))
{
Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
myRigidBody.velocity += jumpVelocityToAdd;
stoppedJumping = false;
}
}
if(CrossPlatformInputManager.GetButton("Jump") && !grounded)
{
if (jumpTimeCounter > 0)
{
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, jumpSpeed);
jumpTimeCounter -= Time.deltaTime;
}
}
if (CrossPlatformInputManager.GetButtonUp("Jump"))
{
jumpTimeCounter = 0;
stoppedJumping = true;
}
}
`