Sphere can jump, but doesn't stop.

I have a sphere (that I’m using like the character) it moves around with this code:

public float speed;

	void FixedUpdate ()
	{
		float moveHorizontal = Input.GetAxis("Horizontal");
		float moveVertical = Input.GetAxis("Vertical");

		Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

		rigidbody.AddForce(movement * speed * Time.deltaTime);
	}

and that work perfectly. But I wanted to be able to jump. I tried out a couple of jumping scripts I found online, but had the same problem with both: Once I pressed the spacebar my sphere would jump and not stop. It just kept jumping up and down. I think this is because it didn’t know when it had landed, maybe?

Could someone give me some C# code to add to my script that will make it jump once?

Thanks!

in thispost you can find out if the player is grounded (touching the ground) or not. Only allow the player to jump if touching the ground is true.

The charactercontroller has a build in function for this, which is why it’s so commonly used. A rigidbody is mostly used for interaction objects, but it is possible :slight_smile: