From 935ee797dce540b31d96fbdb7c277dee6a2ece8d Mon Sep 17 00:00:00 2001 From: SnekInAScarf Date: Sat, 31 Oct 2026 16:21:31 -0700 Subject: [PATCH] Hop up to the ceiling after holding up on the floor Holding up on the floor for MAX_SECS_TO_UNSTICK hops just high enough to reach a ceiling up to HOP_MAX_HEIGHT (64px) above the slime's top, where it then sticks. With no ceiling in reach it does a little 16px hop. Against a wall, up still climbs it instead. Co-Authored-By: Claude Opus 5.5 --- Characters/player.gd | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Characters/player.gd b/Characters/player.gd index c166b08..909b65f 100755 --- a/Characters/player.gd +++ b/Characters/player.gd @@ -37,6 +37,14 @@ const MIN_LAND_SPEED = 60.0 # Slower impacts than this don't splat. # How long to press opposite direction before unsticking from a wall/ceiling const MAX_SECS_TO_UNSTICK = 0.5 +# Hop: holding up on the floor for MAX_SECS_TO_UNSTICK hops just high enough +# to reach a ceiling up to HOP_MAX_HEIGHT above us (measured from our top). +# With no ceiling in reach it's just a little HOP_NO_CEILING_HEIGHT hop. +const HOP_MAX_HEIGHT = 64.0 +const HOP_NO_CEILING_HEIGHT = 16.0 +const HOP_OVERSHOOT = 2.0 # Aim slightly past the ceiling so we still hit it with some speed. +var timeSpentHoldingUpOnFloor := 0.0 + var isStickingToWall := false var timeSpentUnstickingWall = 0.0 @@ -158,6 +166,14 @@ func _physics_process(delta: float) -> void: elif not is_on_floor(): velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED) + # On the floor, holding up long enough hops up to the ceiling above. Not + # against a wall though, where up climbs it instead. + if is_on_floor() and not isStickingToWall and verticalInput > 0: timeSpentHoldingUpOnFloor += delta + else: timeSpentHoldingUpOnFloor = 0.0 + if timeSpentHoldingUpOnFloor >= MAX_SECS_TO_UNSTICK: + timeSpentHoldingUpOnFloor = 0.0 + velocity.y = -sqrt(2.0 * get_gravity().y * _get_hop_height()) + # Horizontal Input Controls # If sticking to a wall, pressing away from it long enough gets us unstuck. if isStickingToWall and not is_on_floor(): @@ -236,6 +252,13 @@ func _physics_process(delta: float) -> void: _update_sprite_rotation(delta) +# How high to hop: up to the ceiling above us if there's one in reach. +func _get_hop_height() -> float: + var hit := move_and_collide(Vector2(0, -HOP_MAX_HEIGHT), true) + if hit and hit.get_normal().y > 0.5: + return hit.get_travel().length() + HOP_OVERSHOOT + return HOP_NO_CEILING_HEIGHT + # Moves speed towards target: GROUND_ACCEL when speeding up, GROUND_FRICTION # when slowing down or stopping. func _accelerate(speed: float, target: float) -> float: