I'm trying to wrap my mind around the Platformer controller script from the 2d Platformer tutorial, but I have some doubts I don't seem to be able to solve by reading the script and reference manuals. Here goes. On this piece of code:
function ApplyJumping () {
// Prevent jumping too fast after each other
if (jump.lastTime + jump.repeatTime > Time.time)
return;
if (controller.isGrounded) {
// Jump
// - Only when pressing the button down
// - With a timeout so you can press the button slightly before landing
if (jump.enabled && Time.time < jump.lastButtonTime + jump.timeout) {
movement.verticalSpeed = CalculateJumpVerticalSpeed (jump.height);
movement.inAirVelocity = lastPlatformVelocity;
SendMessage ("DidJump", SendMessageOptions.DontRequireReceiver);
}
}
}
I don't get what the
if (jump.enabled && Time.time < jump.lastButtonTime + jump.timeout)
bit does. The variables are pretty self-explanatory, (jump is a custom class with a number of variables, timeout is a constant previously set at 0.15)
To me this looks as if jumping will only occur if the button is pressed before timeout time has passed after it was pressed last time. Which doesn't make sense (I can only jump if I keep jumping?). I'm sure I'm missing something, I just can't find out.
Please let me know if you need more details.