Object sometimes jumps double what it should.

Hi guys I have a small problem with my project, when I hit space my character jumps a certain height but every so often my character will jump double the height its meant too, I’m not really sure why it is doing this. Here is my code at the moment.

public class NewPlayerMovement : MonoBehaviour {

	public Vector2 jumpVector;
	public bool canJump;
	public bool touchingPlatform;

        void Update ()
	{

		if (Input.GetKey (KeyCode.Space)) 
		{
			Jump();
		}
		if (touchingPlatform) 
		{
			canJump = true;
		}
		if (!touchingPlatform) 
		{
			canJump = false;
		}
	}
 	void Jump()
	{
		if(touchingPlatform && canJump)
		{
			GetComponent<Rigidbody2D>().AddForce (jumpVector, ForceMode2D.Impulse);
		}
	}
	void OnCollisionEnter2D(Collision2D col) 
	{	
		if (col.gameObject.name == "Floor") 
		{
			touchingPlatform = true;

		}
	}
	void OnCollisionExit2D(Collision2D col)
	{
		if(col.gameObject.name == "Floor")
		{
			touchingPlatform = false;
		}
	}
}

Any help would be greatly appreciated, cheers. - Lewis

try changing this-

if(touchingPlatform && canJump)

to

if(touchingPlatform && canJump == true)

:slight_smile: