Combat & movement 5 min read

Design Sprint Stamina and Double Jumps

Design two movement abilities with readable limits, consistent timing and clean resets.

Measure stamina in seconds

Multiply the drain and recovery rates by the elapsed frame time. At 0.36 stamina per second, a full meter lasts about 2.8 seconds of sprinting. Use the same normalized value for the meter width. If the bar reaches zero, require the player to release Shift and recover a minimum amount before trying again.

Make the second jump intentional

Listen to the built-in jump request so touch controls can request the extra jump, too. Arm the boost after a normal jump enters free fall. Keep a short delay after takeoff so a held input cannot spend both jumps immediately. Clear the flag on landing.

Map the edge cases

Try sprinting while idle, releasing the key at zero, pressing jump at the edge of a platform and resetting in the air. When racing affects rewards, validate results on the server. Keep the prototype movement rules separate from the prize logic.

Lay out a course with four useful tests

Use a plain baseplate to build a straight lane, a low step, a short gap and a higher platform. Give the avatar space to land after each obstacle. Keep the route short enough to repeat the whole test within a minute. Mark the beginning and end of the lane with distinct colors so you can see where a sprint starts and stops. A flat lane reveals stamina problems without interference from falling and landing. The two gaps should require different decisions: one ought to be comfortably reachable with a normal jump, while the other can demonstrate what the extra airborne jump adds. Adjust those distances after measuring how the actual avatar moves.

Model stamina as a small state machine

Start with three situations: stamina available, stamina draining and stamina recovering. Represent the resource as a number between zero and one, where one is full. Using this range means the same number can drive the meter without converting to percentages every frame. When movement is fast enough to count as a sprint, reduce stamina by the drain rate multiplied by elapsed seconds. After the input ends, recover it with the same calculation using a positive rate. Clamp at both ends. Include an exhausted flag so boosting does not switch on and off rapidly at the bottom of the meter. Clear that flag after enough reserve has returned and the player's control has been released.

local function stepStamina(current, deltaTime, isBoosting)
    local rate = isBoosting and -0.36 or 0.22
    return math.clamp(current + rate * deltaTime, 0, 1)
end

Permit the extra jump in a narrow window

A second jump should be an airborne choice, so keep track of the first jump and whether the extra jump has already been used. When the character leaves the floor because of a normal jump, arm the air action after a short delay. Spend the air action only when the Humanoid is in free fall and receives a new jump request. Clear the state on landing and when a new character is created. Try holding the control down during takeoff, then try two distinct taps. If the second launch fires during the initial takeoff, increase the delay slightly or check your state transitions. Treat stepping off a ledge separately from jumping off it. Here, a ledge drop does not arm the ability.

Test mixed movement rather than only the ideal input

Walk the lane at normal pace. Hold Shift while stationary and check that standing still does not drain the meter. Run until exhaustion, release the control and check that recovery becomes visible. Try jumping just before the meter empties and use the extra boost on the wider gap. Then reset the character while still in the air. When the new character appears, the meter and airborne flags should both return to their starting behavior. Run the jump test once with Studio's touch emulator. The built-in jump control should still produce the request that your air-jump logic listens for, even without a keyboard. For a touch sprint button, wire it into the same held state as the keyboard control.

Decide what the server needs for a real course

For a local prototype, focusing on how movement feels is fine. If you use completion times to award currency or rank players, keep the award decision in your own server logic. At a minimum, record the start, route progress and finish there. Fast motion on the client alone does not establish that a course was completed properly. Also decide which code owns Humanoid movement speed. A sprint script that writes a walking speed repeatedly can conflict with a slow zone or a pace selector. Make one movement controller combine a default pace and defined modifiers once you start using these mechanics together. Write down whether an airborne jump can spend stamina before adding that interaction.

Related scripts