Camera Follow 2D
Moves its virtual camera after Target, with a deadzone, damping and lookahead.
component camera.CameraFollow2D
On this page
Usage
Needs Virtual Camera 2D on the same node.
Try it
Snap after a teleport
The target teleports eight world units; very slow damping makes the camera's response easy to see.
Change Snap Distance from 20 to 1: the camera snaps to the teleported target. Reset restores the original slow follow.
Scene9 nodes
Scriptmain.aes
package demo
import "aego/physics"
// Let physics create the body and the camera observe the initial pose, even
// when several fixed steps happen in one rendered frame.
script Launch {
var physicsReady bool
var frames int
func FixedUpdate(dt float) {
physicsReady = true
}
func Update(dt float) {
if physicsReady {
frames++
if frames == 2 {
body := node.Get<Body2D>()
body.Teleport(Vec2{-18, -2}, 0)
body.SetVelocity(Vec2{0, 0})
}
}
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Target | NodeRef | none | Node to follow; its interpolated position is used. |
| Deadzone | Rect | (0.4, 0.4, 0.2, 0.2) | Area of the view, in 0..1 of its width and height, where the target moves without moving the camera. |
| Damping | Vec2 | (6, 6) | How fast the camera catches up, per second on each axis. 0 follows rigidly. |
| Lookahead | Vec2 | (0.25, 0) | Seconds of target velocity the camera looks ahead on each axis. |
| Max Lookahead | Vec2 | (3, 1) | Largest lookahead in world units on each axis. 0 is unlimited. |
| Lookahead Smoothing | float | 3 | How fast the lookahead changes, per second. 0 changes at once. ≥ 0 |
| Snap Distance | float | 20 | A target jump longer than this, in world units, moves the camera at once. 0 never snaps. ≥ 0 |
Methods
Snap method
func (CameraFollow2D) Snap()
Moves the camera onto the target at once, for example after a teleport.
Related guides
- Follow Camera Follow 2D moves its virtual camera after Target.
- Cameras 2D A Camera 2D draws the view; virtual cameras decide where it looks.