09 · Physics & collisions · 2D and 3D

Collision response

Slide along walls instead of sticking to them.

Spotting a collision is only half the job. The other half is deciding what happens next. If the game cancels the whole move whenever you touch a wall, pushing diagonally into it freezes the player. Removing only the part of the movement that goes into the wall lets the rest carry on, so the character glides along it.

←→↑↓ or WASD moveM slide / stopDrag on the room to move

Try this: Hold up and right into the top wall. On Stop you freeze; on Slide you keep gliding along it.

what you pressedwall normalmovement that happened

Time stuck on walls 0.0 s

Push diagonally into any wall.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

On collision, slide instead of stopping: remove only the velocity component pointing into the wall (velocity minus its dot with the normal times the normal), keep a skin width of about 0.01 units, and resolve corners one axis at a time so they never snag.

45 words · one sentence to paste as is

Where it's used

Common mistakes

Cancelling the whole move on any contact (sticky walls), pushing out along the shortest axis (characters pop through thin corners), skipping the skin width so the next frame starts inside the wall, and leaving velocity untouched so it grows while pressed into a wall.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.