Skip to content

Floaty glide parachute toggle

const GLIDE_GRAVITY_SCALE   = 0.20   // fraction of normal gravity while gliding
const GLIDE_MAX_FALL_SPEED  = 90.0   // much lower terminal velocity than normal falling
const GLIDE_AIR_ACCEL       = 500.0  // horizontal drift control while gliding
const GLIDE_FORWARD_RATIO   = 0.35   // optional: convert some fall speed into forward speed

state is_gliding = false

function handle_glide_input():
    can_start = (not is_grounded) and (velocity.y > 0) and (not is_wall_sliding)
    if input.is_down("glide") and can_start:
        is_gliding = true
    elif not input.is_down("glide") or is_grounded:
        is_gliding = false

function apply_glide_physics(dt):
    velocity.y = min(velocity.y + GRAVITY * GLIDE_GRAVITY_SCALE * dt, GLIDE_MAX_FALL_SPEED)

    // Horizontal drift uses the hybrid air-control model (section 7), just
    // with its own accel constant so gliding feels distinctly floatier.
    input_dir = get_input_direction()
    velocity.x = move_toward(velocity.x, input_dir * MAX_SPEED, GLIDE_AIR_ACCEL * dt)

    // Optional "true glide" variant: trade some vertical speed for forward
    // speed instead of just capping the fall, so it reads as gliding through
    // the air rather than merely falling slowly.
    // velocity.x += velocity.y * GLIDE_FORWARD_RATIO * dt * facing_direction

function cancel_glide():
    is_gliding = false

function update(dt):
    handle_glide_input()

    apply_horizontal_acceleration(dt)
    handle_jump_input()

    if is_gliding:
        apply_glide_physics(dt)
    else:
        apply_gravity(dt)

    integrate_position(dt)
    integrate_vertical(dt)
    if is_grounded or is_wall_sliding:
        cancel_glide()

How it works

At its simplest, gliding is a temporary override of two of the same constants already in play elsewhere in this document: gravity scale and terminal fall speed. While the toggle is active and its entry conditions hold (airborne, already falling, button held), GRAVITY is scaled down heavily and the fall-speed clamp drops from MAX_FALL_SPEED to something much lower — that alone is enough to produce a floaty "parachute" feel: the descent visibly slows the moment the button is pressed, and speeds back up the instant it's released or the ground is touched.

The entry check (can_start) matters: gliding is generally only sensible while already falling, not while still rising from a jump (that would let you cancel jump gravity into an instant float, which is a different, usually unintended, mechanic) and not while wall-sliding, since that's already a separate reduced-fall-speed state and the two shouldn't stack.

The commented-out "true glide" line is the more aerodynamic variant worth calling out as a distinct option: rather than just capping vertical speed, it converts a portion of the current fall speed into forward speed each frame (velocity.x += velocity.y * GLIDE_FORWARD_RATIO). That produces motion that actually reads as gliding through the air — trading height for distance — rather than merely falling in slow motion, at the cost of being a bit more work to tune so it doesn't run away with itself (usually paired with its own horizontal speed cap).