How to Make a Double Jump Script

How to make a double jump script is usually the second thing on a new developer's mind after they've figured out how to make a character move left and right without falling through the floor. It's a bit of a rite of passage in game development because, let's be real, a single jump is fine, but a double jump is where the fun actually starts. It gives your character that snappy, arcade-like feel that makes platformers so addictive to play. Whether you're working in Unity, Roblox, or Godot, the logic behind it is actually pretty similar across the board.

The core idea is pretty straightforward: you're essentially just telling the game to keep track of how many times the player has pressed the jump button since they last touched the ground. Once they hit the ground, you reset that counter. If they're in the air and the counter is low enough, you let them fly one more time. It sounds simple, but getting it to feel right—that's where the real magic happens.

The Basic Logic Behind the Leap

Before we start typing out lines of code, we need to understand the "state machine" logic. Imagine your character has a little notepad in their pocket. On that notepad is a number called jumpsLeft.

When the character is standing on the grass, jumpsLeft is set to 2. When they press the spacebar, they launch into the air, and you subtract 1. Now they have 1 jump left. If they press spacebar again while they're still in the air, they launch again, and you subtract another 1. Now they have 0 left, and no matter how hard they mash that button, nothing happens until their feet touch the dirt again.

This is the foundation of how to make a double jump script. You need a way to check if the player is "grounded" and a way to limit the input.

Doing It in Unity with C

Unity is probably the most common place people start asking this question. If you're using a Rigidbody2D for a side-scroller, you can get a double jump working in about ten minutes.

First, you'll need a few variables. You need one for the jump force, one for the current jump count, and one to keep track of the maximum jumps allowed. It's always better to use a variable for the maximum jumps rather than hard-coding the number "2" everywhere, just in case you decide later that a triple jump would be even cooler.

csharp public float jumpForce = 5f; private int jumpsRemaining; public int maxJumps = 2; private Rigidbody2D rb; public bool isGrounded;

In your Update() method, you'll listen for that button press. But here's the kicker: you don't just check if they're on the ground. You check if jumpsRemaining > 0.

csharp void Update() { if (Input.GetKeyDown(KeyCode.Space) && jumpsRemaining > 0) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); jumpsRemaining--; } }

Now, the most important part is resetting that counter. You usually do this in OnCollisionEnter2D or by using a Raycast to detect the ground. When the character hits a surface tagged as "Ground," you set jumpsRemaining = maxJumps. If you forget this step, your player gets one double jump at the start of the level and then spends the rest of the game walking like a mere mortal.

The Roblox Approach (Luau)

Roblox is a different beast because the Humanoid object handles a lot of the physics for you. However, the logic of how to make a double jump script remains largely the same, though you'll be interacting with the UserInputService and the character's state.

In Roblox, you'd typically use a LocalScript. You want to listen for the Jump property or the JumpRequest event. One little trick in Roblox is that the JumpRequest event fires very rapidly, so you need a "debounce" or a small delay to make sure one tap doesn't consume both jumps instantly.

You'll store a variable like canDoubleJump and hasDoubleJumped. When the player jumps normally, you wait a fraction of a second, then set canDoubleJump to true. If they press jump again while that's true, you give them a manual boost using Velocity or by changing the JumpPower temporarily.

The cool thing about Roblox is how easy it is to play an animation during that second jump. A quick front-flip or a little puff of smoke under the feet makes the double jump feel intentional rather than just a physics glitch.

Making It Feel "Juicy"

Let's talk about "game feel." A script that just adds vertical velocity is technically a double jump, but it might feel a bit stiff. If you want your script to stand out, you need to add some polish.

Coyote Time is a huge one. This is named after Wile E. Coyote, who stays in the air for a second before falling. It allows the player to jump even if they've just walked off a ledge. If your script is too strict about being "grounded," players will feel like the game is "eating" their inputs. Give them a 0.1-second grace period where they can still perform their first jump even if they aren't touching the floor.

Another tip: Variable Jump Height. If the player just taps the button, they should do a small hop. If they hold it, they should go higher. This is usually handled by checking when the player releases the jump button and cutting the upward velocity in half if they aren't at the peak of their jump yet.

Common Pitfalls to Avoid

When you're figuring out how to make a double jump script, you're going to run into some bugs. It's just part of the process.

  1. The Infinite Jump: This happens when you forget to subtract from your jump counter. Suddenly, your player is flying like Superman because every button press adds more force.
  2. The Grounding Glitch: If your ground detection is too sensitive, it might think a wall is the ground. The player could then "wall jump" infinitely by just mashing space against a vertical surface. To fix this, make sure your raycast or collision check is only looking down.
  3. Velocity Stacking: If you just add force (AddForce), the second jump might feel inconsistent depending on whether the player is falling or rising. It's often better to set the velocity directly for that second jump so the "boost" is always the same height regardless of momentum.

Why Does This Even Matter?

You might think, "It's just a jump, who cares?" But movement is the primary way a player interacts with your world. If the movement feels sluggish or restricted, the player is going to get frustrated. By mastering how to make a double jump script, you're actually learning about player agency. You're giving them more tools to explore the environment you've built.

Think about games like Celeste or Hollow Knight. Their jump scripts are incredibly complex under the hood, with dozens of tiny tweaks to make the character feel responsive. Your double jump script is the first step toward that level of polish.

Wrapping Things Up

At the end of the day, writing the code is only half the battle. You'll spend the other half tweaking numbers. Is the second jump too high? Is it too weak? Does it need a sound effect? (The answer to that last one is always yes).

Once you've got your basic counter and ground reset working, don't be afraid to experiment. Maybe the double jump only works after collecting a power-up. Maybe it recharges over time instead of on ground contact. The beauty of knowing how to make a double jump script is that once you understand the logic, you can bend the rules to fit whatever weird and wonderful game idea you've got rattling around in your head.

So, go ahead and open your editor, set up those variables, and start jumping. It might take a few tries to get the gravity feeling "heavy" enough or the boost feeling "snappy" enough, but once it clicks, you'll know. There's no feeling quite like finally nailing the perfect jump height and watching your character sail across a gap they couldn't reach five minutes ago. Happy coding!