My jump code seems to be broken, the character's flags for jumping appear to be working strangely.

var moveSpeed:float = 1.0;
var y : float;
var isJumping:byte = 0;
var isOnGround:byte = 1;
var maxHeight:int = 2;

function Update () 
{//if the player is eligible to jump, pressing W will send them upwards and make them inelegible to jump until they have landed.
	if(isOnGround == 1)
	{
		if(Input.GetButton("forward"))
		{
			rigidbody.AddForce(Vector3.up*50);
			isOnGround = 0;
		}
		
	}
	if(Input.GetButton("forward") == false)
	{
		isJumping = 0; //the player is not jumping if the button is not pressed
	}
	

	if(transform.position.y <= 0)//If this condition is removed, changed or replaced with anything else, the player's jumps go on forever. Until the button is released, of course.
	{
		isOnGround = 1;
	}
	
}

1 Answer

1

try to use character controller instead of rigidbody