Inputs not working. (SOLVED)

I’m new to Unity and watched a Tutorial on a basic game.
I have space for jump, but when I press space, it sometimes jump. It doesn’t always jump.
Here is my code for the controls:

Sorry if this is the wrong thread.

The isFalling should be set to true inside the if statemen.

 if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
        {
    isFalling = true;
                GetComponent.<Rigidbody>().velocity.y = jumpHeight;
        }

Not outside it.

Its probably not the input that is being missed, but since (as korno has said) you had the isfalling being set to true outside the if, it was being set every frame. Meanwhile, OnCollisionStay, where you are setting isfalling to false, is only ran every fixedupdate, which depending on your settings could mean that some updates the isfalling was never set back to false since OnCollisionStay was not ran.

Now when I jump, I can jump again in the air.

I dont know javascript, so hopefully this is coded right

Click for code

#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;

private var hasFixedUpdate = false;

function FixedUpdate()
{
    hasFixedUpdate = true;
}

function Update ()
{
    //Move the ball.
    var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    rotation *= Time.deltaTime;
    GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
      
    if (Input.GetKeyDown(KeyCode.Space) && isFalling == false && hasFixedUpdate == true)
    {
        GetComponent.<Rigidbody>().velocity.y = jumpHeight;
    }
    isFalling = true;
    hasFixedUpdate = false;
}
function OnCollisionStay ()
{
    isFalling = false;
}

Would this work? Not tested.

No, that didn’t work. Its doing the same thing from the original post.

hehe, aaaa yes, all I did was re-add the problem of fixedupdate.

have a look at how its being done here
http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker

Another way might be like this
Click for code

#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
private var canJump = false;

function Update()
{
    if(Input.GetKeyDown(KeyCode.Space) && isFalling == false)
    {
        canJump = true;
    }
}

function FixedUpdate()
{
    var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    rotation *= Time.deltaTime;
    GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);

    if(canJump == true)
    {
        GetComponent.<Rigidbody>().velocity.y = jumpHeight;
        canJump = false;
    }
    isFalling = true;
}

function OnCollisionStay()
{
    isFalling = false;
}

I get an error:
Assets/Scripts/BallControl.js(24,21): BCE0034: Expressions in statements must only be executed for their side-effects.

oops, do canJump = false, not canJump == false.
Sorry, writing this without a IDE
Ill edit the code.

That fixed it. But, how can I make it so I can move while I jump?

what is your current movement script?
If you are to use the RigidbodyFPSController that I linked above, to move while in the air you would move the movement part of the script out of the if(grounded)

Im using

#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
private var canJump = false;

function Update()
{
if(Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
canJump = true;
}
}

function FixedUpdate()
{
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.().AddRelativeTorque (Vector3.back * rotation);

if(canJump == true)
{
GetComponent.().velocity.y = jumpHeight;
canJump = false;
}
isFalling = true;
}

function OnCollisionStay()
{
isFalling = false;
}

I would want to move right or left while in the air. When I jump, I just move the way I was moving before I jumped.

I dont see any movement code in the script you posted, only jump and rotation.

Nevermind then. I don’t need it that much.