Corner correction moves the character a few pixels when a jump would clip a corner: up to 9 px sideways past the edge of a ceiling, or up to 7 px up onto a ledge it just missed. The player sees a jump that worked and never sees the nudge.
| Case | Correction |
|---|---|
| Head clips a ceiling corner while rising | up to 9 px sideways |
| Falling sideways into the lip of a ledge | up to 7 px up |
| Either one during a dash | up to 12 px |
Corner correction going up: past the edge of the ceiling
Hitting your head by 4 px cuts a jump dead, and the player reads it as the game failing. With a 24 px body under a 40 px hole, jumping straight through means lining up within 8 px of the hole's center. A 9 px correction stretches that window from 16 px to 34, and the player never sees it stretch.
Celeste tries only 4 px, and only toward the side you're already moving.
Corner correction on ledges: up onto the lip
The same idea works sideways. To the player, a fall that misses the top of a platform by one pixel looks like a landing. Without the correction the character slides down the face instead, so the game lifts it onto the lip and stops the fall.
How to implement corner correction
- Check before you move. Once the velocity is decided, ask whether this tick's motion would collide.
- Search for the smallest nudge. Try 1 px, 2, 3, up to the limit: both sides for the head, only up for a ledge. Keep the first one that clears the way.
- Check that the nudge itself is free. Dodging a ceiling must never push the character into a wall.
- Keep the limit small. The nudge happens in one tick, so a big one shows as a jump in position.
The code in Godot 4
func _correct_corners(delta: float) -> void:
var enabled := Lab.on(&"corner_correction")
var dashing := state == State.DASH
var p := params
if velocity.y < 0.0:
var up := Vector2(0.0, velocity.y * delta)
if test_move(global_transform, up):
var limit := p.dash_correction_px if dashing else p.corner_correction_px
var px := _find_nudge(up, Vector2.RIGHT, limit, [1.0, -1.0])
if px != 0.0:
if enabled:
global_position.x += px
func _find_nudge(motion: Vector2, axis: Vector2, max_px: int, signs: Array) -> float:
for i in range(1, max_px + 1):
for s: float in signs:
var shift := axis * (i * s)
if test_move(global_transform, shift):
continue # tampoco cabemos hacia ese lado
if not test_move(global_transform.translated(shift), motion):
return i * s
return 0.0 The ledge case calls the same _find_nudge with Vector2.UP, then caps velocity.y at zero.
Quick answers
How many pixels should corner correction use?
A few. Celeste uses 4 px for the head. This demo uses 9 px for the head and 7 for ledges, on a 24 px body and 40 px tiles.
Is corner correction only for the head?
No. If a fall misses the top of a ledge by a few pixels, lift the character onto it. It's the same technique pointed sideways.
Discussion
Comments are hosted on GitHub Discussions — sign in with GitHub to reply.