Shake
In Try it, the crate drops every two seconds and its script calls camera.Shake(0.9) when it lands. Raise Max Angle or lower Exponent and Decay on the camera to feel the difference.
Shake is driven by trauma, a value from 0 to 1 per output. camera.Shake(0.4) adds trauma, which fades by Decay per second. The view moves by up to Max Offset and turns by up to Max Angle, scaled by trauma to the power Exponent, so small hits stay subtle. Without a Camera Shake 2D on the active camera the defaults are used.
The motion comes from deterministic noise, so a replay shakes the same way, and it never touches the node's transform or the game's random numbers.
Trauma adds up and fades in real time. With the default Decay of 1.5 a hit of 0.6 is gone in 0.4 seconds:
package demo
import (
"aego/camera"
"aego/log"
)
script Hits {
var frames int
func Ready() {
camera.Shake(0.6)
log.Info("hit, trauma " + string(camera.Trauma()))
}
func Update(dt float) {
frames++
if frames % 6 == 0 && frames <= 30 {
log.Info("trauma " + string(camera.Trauma()))
}
if frames == 30 {
camera.Shake(0.5)
camera.Shake(0.8)
log.Info("two hits, capped at " + string(camera.Trauma()))
}
}
}
On this page
Accessibility
Settings → Accessibility → Screen Shake scales every shake; 0 turns it off. Reduce Motion turns shake off and removes lookahead. Trauma still fades, so gameplay that reads camera.Trauma() is not affected.
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Scene8 nodes
Scriptmain.aes
package demo
import (
"aego/camera"
"aego/physics"
)
// Drop lifts the crate every few seconds; each landing shakes the camera.
script Drop {
@export var Every float = 2
@export(min=0, max=1)
var Hit float = 0.9
var t float
var start Vec2
func Ready() {
start = node.Transform2D().Position
}
func Update(dt float) {
t += dt
if t >= Every {
t = 0
body := node.Get<Body2D>()
body.Teleport(start, 0)
body.SetVelocity(Vec2{0, 0})
}
}
func OnCollisionEnter(other NodeRef, c physics.Contact) {
camera.Shake(Hit)
}
}