Room Camera
A room camera cuts the world into screen-sized rooms and shows the one the character is in. It does not follow the character inside a room. When the character crosses into the next room, the camera slides over in a set time. When the character lands far away, the screen fades out, moves, and fades in.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Room Camera" to my game.
What it should do: Showing one whole room at a time gives the designer full control of what the player sees, makes puzzles and ambushes fair, and removes the need for the camera to guess. The player always knows where the edges are.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> settled
settled: Settled
sliding: Sliding
cutting: Fading
settled --> sliding: enters next room
sliding --> settled: slide is done
settled --> cutting: lands far away
sliding --> cutting: lands far away
cutting --> settled: fade is done
```
Use these starting values:
- roomWidth: 16 units
- roomHeight: 9 units
- slideTime: 0.5 s
- cutTime: 0.4 s
- margin: 0.4 units
Watch out for these common mistakes:
- Rooms at negative positions: Tell your AI: find the room by rounding down, never by cutting off the decimals.
- Standing on a doorway: Tell your AI: let the character go a small distance into the next room before the camera goes, and the same distance back before it returns.
- The corner: Tell your AI: work out the room for both directions together and slide once, straight to it.
- A far jump: Tell your AI: for anything more than one room away, fade out, move and fade in.
- A long frame: Tell your AI: measure the slide in time, and put the camera exactly on the room at the end.
- Running on during a slide: Tell your AI: when a slide ends, look at the character again and slide on if it is in another room.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Showing one whole room at a time gives the designer full control of what the player sees, makes puzzles and ambushes fair, and removes the need for the camera to guess. The player always knows where the edges are.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Settled → Sliding: enters next room
- Sliding → Settled: slide is done
- Settled → Fading: lands far away
- Sliding → Fading: lands far away
- Fading → Settled: fade is done
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| roomWidth | 16 units | The width of one room, the same as the width of the screen. Every room is the same size. |
| roomHeight | 9 units | The height of one room, the same as the height of the screen. |
| slideTime | 0.5 s | How long the slide from one room to the next takes. Half a second is quick enough not to feel like a wait and slow enough to see where you went. |
| cutTime | 0.4 s | The whole fade for a far jump: black by the half, clear again at the end. |
| margin | 0.4 units | How far into the next room the character must be before the camera goes, and how far back to come back. It stops a camera that flips when the character stands on a doorway. |
What usually goes wrong
Rooms at negative positions
Cutting off the decimals instead of rounding down puts the positions from minus one to one into the same room, so the room at the origin is twice as wide, and the camera jumps strangely there.
Fix: Tell your AI: find the room by rounding down, never by cutting off the decimals.
Standing on a doorway
A character standing exactly on the border, or moving a little back and forth over it, makes the camera slide to one room and back, again and again.
Fix: Tell your AI: let the character go a small distance into the next room before the camera goes, and the same distance back before it returns.
The corner
A character that passes a corner between four rooms can trigger two slides in a row, one sideways and one up, and the camera zigzags.
Fix: Tell your AI: work out the room for both directions together and slide once, straight to it.
A far jump
A slide to a room ten rooms away sweeps through every room between at a crazy speed, or takes too long if the time is stretched with the distance.
Fix: Tell your AI: for anything more than one room away, fade out, move and fade in.
A long frame
If the slide moves a fixed amount per frame, a long frame goes past the new room and the camera overshoots, or the time depends on the frame rate.
Fix: Tell your AI: measure the slide in time, and put the camera exactly on the room at the end.
Running on during a slide
The character keeps running during a slide and is already in the room after the next one when it ends. If the game forgets this, the camera stays one room behind.
Fix: Tell your AI: when a slide ends, look at the character again and slide on if it is in another room.
How to check it works
- The character moves around inside one room. Three seconds pass: The camera does not move and stays exactly on the centre of the room.
- The character is in the first room and steps half a unit into the room on the right. One tick passes: A slide to the room on the right begins, and the camera has not moved yet.
- A slide has begun. Half the slide time passes, and then the rest: In the middle the camera is about halfway, and the slide ends after the full slide time.
- A slide ends. You look at the camera: It sits exactly on the centre of the new room.
- The character moves back and forth over the border by less than the margin. Three seconds pass: The camera never starts a slide, in either room.
- The character stands just left of the origin. You ask for its room, and then it crosses to the right of the origin: The first room has the number minus one, and the camera slides to room zero.
- The character appears six rooms away. The cut runs: The screen goes black, the camera moves while it is black, the screen clears again, and no slide happens in between.
- The character crosses the corner between four rooms. The slide ends: There was exactly one slide, straight to the room diagonally across.
- A slide has begun. One tick lasts two seconds: The camera sits exactly on the new room.
- The character runs across several rooms at 20 units per second. Four seconds pass: The camera slides room by room without a fade, and when the character stops it shows the room it is in.
Works well with
- Knockback: A push over a border starts a slide and a stun at once. Protection keeps the character from being hit again right after the slide. Do not let a push carry the character into the next room during a slide.
Clashes with Camera Look-Ahead: A look ahead inside a room would show a strip of the next room or empty space. Use one of them. In a game with rooms, set the look distance to zero.
Clashes with Camera Dead Zone: A box that lets the camera drift inside the room fights the fixed view. Use the dead zone in open levels and the room camera in room-based ones.
Common questions
what do i tell my ai to add a room camera
Paste this: Add a room camera: cut the world into rooms of 16 by 9 units, show the room the character is in, and slide to the next room in half a second when the character is 0.4 units into it. For a room more than one away, fade out, move and fade in. Find rooms by rounding down.
how does a screen-by-screen camera work
The world is a grid of rooms the size of the screen. The camera sits in the middle of the current room and stays there. It moves only when the character walks into another room, by sliding across.
why does my room camera jump back and forth at the door
The character is standing on the border and the room changes with every tiny move. Make the character go a small distance into the next room before the camera goes, and the same distance back before it returns.
why is my room at the origin twice as big
The room is probably found by cutting off decimals. Numbers just below zero then land in room zero, together with those just above. Use rounding down.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 14 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it