implementing jumping properly

So i’m making my first game ever, i’m wtching a tutorial but i don’t want to copy it fully.

I implemented a jumping in the game but it’s now to good because if you hold down space you fly away and if you tap space for a really short time you don’t jump high enough.

so this is what i wrote:

if (Input.GetKey(KeyCode.Space)){
rb.AddForce(0, upForce * Time.deltaTime, 0, ForceMode.VelocityChange);
}

How can i make it so that after i press space i can’t press it until i land?

Change ForceMode to Impulse. Also, jumping occurs in one frame, so no need to multiply with Time.deltaTime. But make sure that you cannot jump in the air again, or you will still fly away (no matter how you jump).

For that you need to detect whether you are grounded or not. One way to do so is cast a ray downwards and check the distance to the ground. If you are a beginner it’s probably best if you follow some tutorial for all this first, since most tutorials on jumping will cover one way or the other of preventing in-air jumps.

1 Like