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!