AddForce problem

Hi there! I’m using AddForce to make a character jump. But when I’m hitting Space very often - he flies like a rocket. How to fix that? Thank you!

1

void Update () 
	{
		horizontal = Input.GetAxis("Horizontal");

		if (Input.GetKeyDown (KeyCode.Space) && can_jump == 1) 
		{
			if (horizontal == 0)
			{	
				animator.SetInteger("jump", 1);
				gameObject.GetComponent<Rigidbody>().AddForce(0,200,0);
			}
			else
			{
				if (horizontal > 0)
				{
				   animator.SetInteger("jump_ahead", 1);
				
				   gameObject.GetComponent<Rigidbody>().AddForce(0,200,100);
				}
				if (horizontal < 0)
				{
					animator.SetInteger("jump_ahead", 1);

					gameObject.GetComponent<Rigidbody>().AddForce(0,200,-100);

				}
			}

		}

		if (Input.GetKeyUp (KeyCode.Space)) 
		{
			animator.SetInteger("jump", 0);
			animator.SetInteger("jump_ahead", 0);
		}
	}

Allow your player to only jump if he is grounded.

Set a isGrounded boolean that you check for being true before adding jump force to the player. Once the player jumps set this boolean to be false and again set it to true when player lands on the ground to allow player to jump again. You can check the collision of player with ground to set this boolean to be true.