Why tune the camera
The camera is the part of a 2D game players never notice when it is right and always notice when it is wrong. A camera locked to the player shakes with every small step. A camera that lags too much loses the player in fast sections. Small settings make the difference, and they are hard to judge from numbers in an inspector. Here you tune them on a level you can play, and the game keeps running while you move the sliders.
The settings
Deadzone. A box in the middle of the screen where the player can move without the camera moving. A small horizontal deadzone stops the jitter of short steps. A taller deadzone keeps small jumps from bouncing the view. Smoothing. How long the camera takes to catch up, in seconds, separately for horizontal and vertical. Zero snaps. Lookahead. Shifts the view in the direction the player is moving, so they see what is coming. Lookahead time softens the shift when the player turns around. Vertical offset. Places the player a little lower or higher on screen. Platformers usually show more sky than floor. Platform lock. The camera only moves up and down when the player lands, so jumps do not drag the view. It still follows a long fall. Bounds. Stops the camera at the edges of the level. Pixel snap. Rounds the camera to whole pixels so pixel art does not shimmer.
See exactly what the player sees
The game view shows the player's screen by default. Switch to Overview to pull the view back: the level stays visible all around, and a white frame marks the area the player can see, with everything outside dimmed. Watch the frame lag, lead and stop at the level edges as you change the settings. Use the Screen buttons to try 16:9, 16:10, 4:3 and wide or tall phone screens. A tall phone screen shows far less to the sides, so it usually needs more lookahead and a smaller deadzone.
Screen shake that feels good
Shake uses trauma. Each hit adds trauma between 0 and 1, and trauma fades over time. The shake strength is trauma squared, so small hits give a gentle nudge and big hits really rattle. The motion comes from smooth noise rather than random jumps, so it reads as a hit instead of a glitch. A short zoom punch on top sells impacts even more. Press X or the Hit button to feel it.
Using the script
| Engine | How |
|---|---|
| Godot 4 | Add a Camera2D to your scene, attach follow_camera.gd and drag your player into Target. If the player is a CharacterBody2D, platform lock reads is_on_floor() by itself. Call add_trauma(0.4) from anywhere to shake (Pro). |
| Unity | Add FollowCamera2D.cs to an orthographic camera and set Target. Set Pixels per unit to match your sprites before you export. For platform lock, set isGrounded from your player controller. Call AddTrauma(0.4f) to shake (Pro). |
| Phaser 3 (Pro) | Create the controller in create() with the camera and the player sprite, then call update(delta) every frame. |
The scripts use the same math as the preview: exponential smoothing that does not depend on the frame rate, deadzone tracking, lookahead from the player's velocity and trauma based shake. What you tune here is what you get in your game.
Is anything uploaded?
No. The test level, the camera and the script are all made in your browser.