26 · Camera · 3D (third-person)

3D camera collision

Stop the camera going through walls.

A third-person camera sits a few metres behind the player. Back the player into a wall and, without collision, the camera ends up inside or behind it and the screen fills with wall. A sphere cast from the player to where the camera wants to be finds the first obstacle and pulls the camera in front of it.

←→ orbit the camera↑↓ move the playerC collision on/offDrag to orbit

Try this: Orbit the camera behind the wall with collision off: the view is blocked. Turn it on (C) and the camera slides in front of the wall.

cameraview coneblocked view

Orbit the camera toward the walls.

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.

Add third-person camera collision: sphere-cast from the player's head toward the desired camera position, place the camera at the hit distance minus a small padding, pull in instantly but ease back out over 0.3 s, and ignore the player and small props.

42 words · one sentence to paste as is

Where it's used

Common mistakes

Raycasting with a thin ray (the near plane still clips walls), colliding with the player or small props so the camera jitters, easing in slowly so walls block the view for a moment, and snapping back out so the camera pumps.

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.