I’m pretty new to coding but this code does work. My problem with it is when I press the jump key it doesn’t always work. I’m using it for a platformer and as great as difficult games can be efficient jumping is kind of required. Is it just my computer or is there a way I can make my control setup better? This is the script I’m using:
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Ball rotation
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
//Ball Jump
if (Input.GetKeyDown (KeyCode.Space) && isFalling == false)
{
Debug.Log(“works”);
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
Any tips would be greatly appreciated.