jump on collision weird behaviour

Hello I have this script below. I want only to move the character left or right and when he collides to give him a jump effect. It seems to work fine. But when the character collides and its on the air and collides again with a new object of same type the jump effect is doubled or tripled and its not like the normal one. If it collides with the same object again the jump effect is back to normal. Anyone knows whats wrong?

var speed : float = 5;
var height : int = 150;
var x : float;

public var distanceTravelled : float;

function OnCollisionEnter( collision : Collision ) {
		rigidbody.AddForce (Vector3.up * height);
}

function Start () {
	
}

function Update () {
     x = Input.GetAxis("Horizontal") * speed * Time.deltaTime; 
     transform.Translate(x, 0, 0);
     distanceTravelled = transform.localPosition.y;
     Debug.Log("Distance:" + distanceTravelled);
}

On each collision you add a force. Instead of adding a new force, you need to “forget” the old force you applied first. You can add the opposite force to the old one before adding the new one for example. I don’t see any method to do it easier. If someone knows one …

I did it with

rigidbody.velocity

instead of
rigidbody.AddForce

and seems to work like i want :slight_smile:

Thanks for the help