Jumping ball jumps at random height when I press Space

I’m trying to make a 2D ball physics puzzle game. Where the player controls a ball through a maze type thing.

When I make the ball jump, It sometimes jumps really high, and sometimes it barely gets off the floor.

Here is the code I am using, It is attached to the ball:
using UnityEngine;
using System.Collections;

public class Control : MonoBehaviour {
	
	public GameObject Ball;
	public float JumpSpeed; 
	public Camera cam;
	public float runSpeed;
	
	// Use this for initialization
	void Start () {
		Time.timeScale = 5.0f;
	}
	
	// Update is called once per frame
	void Update () {	
		
	}
	
	void FixedUpdate () {
            // Jumping code:
		if (Input.GetButtonDown ("Jump") ) {
			Ball.rigidbody.AddForce (Vector3.up * JumpSpeed);
        }
		
		Ball.rigidbody.AddForce (-Vector3.left * (Input.GetAxis("Horizontal") * runSpeed));
		float camToX = Ball.transform.position.x;
		float camToY = Ball.transform.position.y;
		float camToZ = cam.transform.position.z;
		
		Vector3 moveCamTo = new Vector3(camToX,camToY, camToZ);
		cam.transform.position = moveCamTo;
    }
	
}

Any help would be Greatly Appreciated!
Also, If any one could help my with not double/multi jumping would be nice too but it isn’t needed :slight_smile:

You are adding a certain amount of force to the ball. If the ball is falling that force is first used to counteract the falling velocity before it can then sends it up (a small amount). If the ball is rising, the force adds to the already rising velocity. One solution is to zero out the current velocity before adding the new force. Just below line 20, insert:

Vector3 v3 = rigidbody.velocity;
v3.y = 0;
rigidbody.velocity = v3;

Another solution would be to replace the AddForce with a direct assignment of velocity:

Vector3 v3 = rigidbody.velocity;
v3.y = JumpSpeed;
rigidbody.velocity = v3;

Your jumpSpeed will be much smaller than the value you used for AddForce(). Note both solutions play with physics in a way that may make the ball appear less realistic.

As for double/multi jumping, one solution would be to only allow the jump if the ball was near/at the ground. If you are bouncing on a simple plane, you could change line 20:

  if (Input.GetButtonDown ("Jump") && Ball.transform.y < someValue) {

…where ‘someValue’ is a height with the ball just off the ground. If the surface is uneven, you’ll have to use colliders or raycasting to determine if the ball is near the ground.