Camera That Follows
You'll replace a camera that's bolted to the player with one that eases, looks ahead, stays inside the level and never gets noticed.
About
A camera locked to the player's position is the default in every engine, and it's why so many first games feel twitchy without anyone being able to say why. The craft is in a few small rules: ease toward the player instead of snapping, ignore tiny movements, look a little ahead in the direction of travel, and never show the void outside the map. Take any game you've built with a level bigger than one screen (a platformer, a top-down thing, or your Walk Cycle Sprite in a long corridor) and give it a camera that nobody comments on, which is the only review a camera ever gets. Itay Keren's free GDC talk 'Scroll Back' is the one reference you need, and the whole job fits in a weekend.
At a glance
- Per requirement
- 25 XP
- Completion bonus
- 150 XP
- Requirements
- 6
- Takes
- One weekend
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- With other people
Requirements
-
1
Record the locked camera, then make it ease toward the player. Start with the engine's default, where the camera sits exactly on the player, and record 15 seconds of it as your before. Then move the camera a fraction of the remaining distance each frame (somewhere between 5 and 15 percent at 60 frames per second) so it drifts into place instead of snapping. Run the easing in the camera's own update after the player has moved, or you'll get a one-frame lag that shows up as jitter. Record the same 15 seconds with the easing on. Video
-
2
Add a dead zone so small movements don't move the camera at all. Draw a box in the middle of the screen, about a third of its width, and only move the camera when the player pushes against its edge. This is what stops the whole screen sliding every time the player shuffles a step. Turn on a debug overlay that draws the box, and record the player moving inside it with the camera still, then pushing out of it with the camera following. Video
-
3
Look ahead in the direction the player is facing. Shift the camera's target 2 to 4 tiles toward the direction of travel, eased so a turn doesn't whip the screen. In a platformer, also hold the vertical position until the player lands, then ease down, because a camera that follows every jump is the fastest way to make someone queasy. Record a run that turns around twice and a jump where the camera stays put until the landing. Video
-
4
Clamp the camera to the level so it never shows outside the map. Take the level's bounds in world units and clamp the camera's position so the edge of the view never passes them. Then add one room transition: a second area with its own bounds, and a quick pan or a cut when the player crosses the doorway. Record the player walking into the corner of the map with no void showing, then crossing into the second room. Video
-
5
Fix the shimmer on pixel art by snapping the camera to whole pixels. If your game uses pixel art, an eased camera lands between pixels and everything shimmers. Round the final camera position to whole pixels (or turn on your engine's pixel snap setting) and keep the easing math in floats underneath. If your game isn't pixel art, add a short cinematic pan to a point of interest and back instead, like a door that opens when a switch is pressed. Record a zoomed-in clip showing the fix, either steady pixels or the pan. Video
-
6
Hand it to someone and ask them what they thought of the camera. Let them play for five minutes without any mention of what you changed, then ask directly. If they say they didn't notice it, you've done it right, because a camera only gets mentioned when it's wrong. Take a photo of them playing, and put their answer and the one value you'd still tune in your write-up. Photo