I’m following a tutorial and there’s a weird bit of code that I can’t get my head around, and isn’t explained in the tutorial. I have a rigidbody sphere on a platform. I can roll the ball back and forth using the following code. Part of the if condition tests to make sure the ball is actually on the platform before allowing me to jump. The problem is, with “isFalling == true;” where it is (where it seems like it should be), I’m still able to double jump. If I move that line outside of the conditional block, though, it behaves the way I want it to. Why is this?
#pragma strict
var RotationSpeed = 100;
var JumpHeight = 8;
private var isFalling;
function Update ()
{
// handle ball rotation
var rotation : float = Input.GetAxis("Horizontal") * RotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque(Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = JumpHeight;
isFalling == true;
}
}
function OnCollisionStay()
{
isFalling = false;
}