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.
Yes, but this code seems to apply if you're grounded. (See the if (controller.isGrounded)), so how does that comment make sense?
– anon77211352I mean, of course, the script comment, not yours :D
– anon77211352Yep, sorry I didn't explian myself properly, if you are grounded but if you pressed before landing, the pressed button is still efective, so you can jump again... Did I explain me better ?... Think about yourself playing games... you press jumpling before landing... but the character doesn't jusmp til grounded...
– anon19470065OK, so if timeout hasn't yet passed, you can press 'jump' again. But not all jumps last the same (if you hold jump, you jump higher), and timeout is still the same. Does that mean that for longer jumps, the button becomes active earlier?. Also, I've searched the cript and found no other call to the DidJump or CalculateJumpVerticalSpeed functions. The game works though...
– anon77211352Still not sure about this. I can't find any other function that performs the jumping, apart from this, and I can't see how this one does the job...
– anon77211352