So my problem here is that when the player holds the space button the addForce function is increased which I don’t want.
So what I want is that if a player holds the space button they can keep jumping continuously if they’re on the ground…
Here is my code:
private void Update()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(1.0f * movementSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (IsGrounded() && Input.GetKey(KeyCode.Space))
{
Debug.Log("IS JUMPING");
_rigidBody.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
}
}