hi, I have a jumping script the longer you press the higher it jumps I have tried to implement it into the unity input system but some bugs were happening like it was sliding in air.
here is the code for the unity input system:
public void Jump(InputAction.CallbackContext context)
{
if (stun == false)
{
if (jumpTimer > Time.time && onGround && context.performed)
{
animator.SetTrigger("takeOf");
Jump();
}
else
{
animator.SetBool("isJumping", true);
}
}
else
{
rb.gravityScale = gravity;
rb.drag = linearDrag * 0.15f;
if (rb.velocity.y < 0)
{
rb.gravityScale = gravity * fallMultiplier;
}
else if (rb.velocity.y > 0 && context.canceled)
{
rb.gravityScale = gravity * (fallMultiplier / 2);
}
}
}
original code:
void FixedUpdate()
{
if (jumpTimer > Time.time && onGround)
{
animator.SetTrigger("takeOf");
Jump();
}
else
{
animator.SetBool("isJumping", true);
}
modifyPhysics();
}
void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
jumpTimer = 0;
}
void modifyPhysics()
{
if(!onGround)
{
rb.gravityScale = gravity;
rb.drag = linearDrag * 0.15f;
if (rb.velocity.y < 0)
{
rb.gravityScale = gravity * fallMultiplier;
}
else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
{
rb.gravityScale = gravity * (fallMultiplier / 2);
}
}
}