Hey all, I’m new and am experiencing issues with my current code. I’m trying to have mario style jumps where the longer you hold the higher you get. I have everything working well, you tap the jump button and you get a short hop, you hold it down you get a nice tall jump but my issues is thus:
If the player holds down the jump button and completes their jump, but does not release the button and then runs to the edge of the platform, the character will jump off the edge and do the full jump.
Which is good for making sure I have platforms far enough away or close enough together for the player. However this is not good to just have the player hold down jump and never have to plan the jump. Any help?
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;
}
}