From 4a760377e6a30a1e0c50561c028096944962560e Mon Sep 17 00:00:00 2001 From: tga Date: Sun, 12 Nov 2023 21:11:14 +0800 Subject: [PATCH] improve jump example --- examples/gravity.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/gravity.js b/examples/gravity.js index 9cdd918dc..a654a41e2 100644 --- a/examples/gravity.js +++ b/examples/gravity.js @@ -33,8 +33,15 @@ player.onGround(() => { // Accelerate falling when player holding down arrow key onKeyDown("down", () => { - if (player.vel.y > 0 && !player.isGrounded()) { - player.vel.y *= 1.1 + if (!player.isGrounded()) { + player.vel.y += dt() * 1200 + } +}) + +// Jump higher if space is held +onKeyDown("space", () => { + if (!player.isGrounded() && player.vel.y < 0) { + player.vel.y -= dt() * 600 } })