Camera Look-Ahead
A look-ahead camera sits a little in front of the character, in the way it is going, so the player sees what is coming. Keep the shift as its own smoothed value, wait a moment before turning it round, hold it for a while after a stop, and keep the camera inside the level.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Camera Look-Ahead" to my game.
What it should do: A camera centred on the character wastes half the screen on where the player has already been. Showing more of the way ahead gives the player time to react to enemies, gaps and turns, and makes fast movement fair.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> centred
centred: Centred
leading: Looking ahead
holding: Holding the look
returning: Coming back
centred --> leading: starts moving
leading --> holding: stops
holding --> leading: moves again
holding --> returning: hold time is over
returning --> leading: moves again
returning --> centred: look is back in middle
```
Use these starting values:
- lookDistance: 3 units
- lookRate: 3 1/s
- followRate: 8 1/s
- holdTime: 0.6 s
- flipDelay: 0.15 s
- minSpeed: 0.5 units/s
Watch out for these common mistakes:
- A fixed share per frame: Tell your AI: use one minus e to the power of minus the rate times the time step, not a fixed share.
- Taps back and forth: Tell your AI: turn the look only after the character has gone the new way for a short time.
- A stop snaps the camera back: Tell your AI: keep the look for a short hold time after a stop.
- Looking past the end of the level: Tell your AI: keep the camera between the left and right limits, after the look is added. If the level is narrower than the screen, sit in the middle.
- Tiny speeds: Tell your AI: treat speeds under a small minimum as standing still.
- Looking where the stick points: Tell your AI: use the real speed of the character, not the input.
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
A camera centred on the character wastes half the screen on where the player has already been. Showing more of the way ahead gives the player time to react to enemies, gaps and turns, and makes fast movement fair.
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
- Centred → Looking ahead: starts moving
- Looking ahead → Holding the look: stops
- Holding the look → Looking ahead: moves again
- Holding the look → Coming back: hold time is over
- Coming back → Looking ahead: moves again
- Coming back → Centred: look is back in middle
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| lookDistance | 3 units | How far ahead the camera looks. About a fifth of the screen width is enough to help without hiding the character. Zero turns it off. |
| lookRate | 3 1/s | How fast the look moves to its goal. Slow enough that a change of direction glides instead of jerks. |
| followRate | 8 1/s | How fast the camera catches up with where it wants to be. Higher is tighter, lower is floatier. |
| holdTime | 0.6 s | How long the look stays after the character stops. A short stop to aim or land must not throw the camera back to the middle. |
| flipDelay | 0.15 s | How long the character must go the new way before the look turns round. It filters out taps back and forth. |
| minSpeed | 0.5 units/s | Slower than this the character counts as standing still. It stops tiny drifts and shaking from picking a direction. |
What usually goes wrong
A fixed share per frame
Moving the camera ten percent of the way each frame looks fine at 60 frames per second and twice as sluggish at 30. A player on a slow machine sees a different camera.
Fix: Tell your AI: use one minus e to the power of minus the rate times the time step, not a fixed share.
Taps back and forth
A player who taps left and right to line up a jump makes the look swing from side to side and the screen sways.
Fix: Tell your AI: turn the look only after the character has gone the new way for a short time.
A stop snaps the camera back
If the look returns to the middle the moment the character stops, every landing and every pause moves the whole screen.
Fix: Tell your AI: keep the look for a short hold time after a stop.
Looking past the end of the level
At the edge of the level the look pulls the camera out over empty space, and the player sees the void behind the world.
Fix: Tell your AI: keep the camera between the left and right limits, after the look is added. If the level is narrower than the screen, sit in the middle.
Tiny speeds
A character that is pushed by a moving platform or sways a little reports a speed close to zero. It picks a direction at random and the look jitters.
Fix: Tell your AI: treat speeds under a small minimum as standing still.
Looking where the stick points
A character pressing into a wall is not moving, but the stick says it is. The camera looks at a wall.
Fix: Tell your AI: use the real speed of the character, not the input.
How to check it works
- A character walks to the right at 5 units per second for three seconds. You look at the camera: It looks 3 units ahead and sits clearly in front of the character.
- A character walks to the left at 5 units per second for three seconds. You look at the camera: It looks 3 units to the left, in front of the character.
- A character that walked to the right stops. Less than the hold time has passed: The camera still looks ahead by the same amount.
- A character that walked to the right stops and stays there. Eight seconds pass: The look is exactly zero and the camera sits on the character.
- A character walks to the right. It goes left for a tenth of a second and then right again, and in another try goes left for a third of a second: The tap changes nothing, the longer move turns the look to the left.
- A character drifts at 0.3 units per second, under the minimum. Two seconds pass: The camera does not look ahead.
- The right limit is 10 and a character runs past it. The look pulls the camera further: The camera never goes beyond 10. With limits that cross, it sits exactly in the middle of them..
Works well with
- Camera Dead Zone: If the dead zone sees the bare position, it hides the look until the character leaves the zone. Add the look to the character's position first, then give the result to the dead zone.
- Vehicle Drift: In a drift the two differ, and the player needs to see where the vehicle is going. Give the camera the real direction of travel, not the way the nose points.
Clashes with Room Camera: A room camera shows one whole room at a time. A look ahead inside it 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.
Common questions
what do i tell my ai to add a look-ahead camera
Paste this: Add a look-ahead camera: shift the camera 3 units in the direction the character really moves, smooth the shift on its own, turn it round only after 0.15 seconds of going the new way, keep it for 0.6 seconds after a stop, and keep the camera inside the level.
how far should a camera look ahead
About a fifth of the screen width to start with. Fast games can go further. If the character drifts to the edge of the screen, it is too far.
why does my camera feel different on a slow computer
The smoothing probably moves a fixed share of the way each frame. Use one minus e to the power of minus the rate times the time step, so it moves the same amount per second at any frame rate.
why does my camera sway when i tap left and right
Every tap turns the look. Turn it only after the character has gone the new way for about a seventh of a second.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 12 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