I’m using a capsule as player(for now) with a ThirdPersonController.js script and a Character Motor component. I would like to allow my player to double jump, can someone help me with some code I can add to the ThirdPersonController.js script so I can allow double jump?
This really wasn’t as bad as I thought it would be!
Line 237 in ApplyJumping checks if you are grounded before allowing a jump. Disable that, and infinite jumps!
function ApplyJumping ()
{
// Prevent jumping too fast after each other
if (lastJumpTime + jumpRepeatTime > Time.time)
return;
//if (IsGrounded()) { //<<-- REMOVE THIS CHECK, WE CAN JUMP MID-AIR!
// Jump
// - Only when pressing the button down
// - With a timeout so you can press the button slightly before landing
if (canJump && Time.time < lastJumpButtonTime + jumpTimeout) {
verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
}
//}
}
From there its a simple matter of adding a var for determining how many jumps in a row are allowed, counting the jumps, checking the jump count before allowing a jump, and resetting the count when you are grounded again!
Hope this helps!