Camera effects
Updated
Camera effects move a camera’s view on top of whatever controls it: a gentle breathing sway, a bounce with each step, the kick of a shot, the shake of an explosion. They make a world feel physical. Each effect is its own component on a camera entity, so you add only the ones you need, and any number of them stack.
Effects offset the view, not the camera entity itself: the entity’s transform, and where the player aims, stay exactly where the controller put them. Disabling an effect, or switching scenes, puts the view back.
Before you start
Section titled “Before you start”- Effects go on camera entities. See Cameras.
- Scripts trigger one-shot effects by calling methods on the component, usually in response to a signal. See Scripting.
Two kinds of effect
Section titled “Two kinds of effect”- Continuous effects run while they are enabled: Breathing and Head Bob. Switch them with
setEnabled(true)orsetEnabled(false). - One-shot effects stay enabled and idle, at no cost, until a script calls
play(): Recoil, Tremor, Impact and Dizzy. Callingplay()again repeats or adds to the effect,stop()ends it, and they never disable themselves.
| Effect | Type | Script class | Kind | Use it for |
|---|---|---|---|---|
| Breathing | comp- |
Camera |
Continuous | A gentle idle sway, like a handheld camera. |
| Head Bob | comp- |
Camera |
Continuous | A step bounce while a first-person camera walks. |
| Recoil | comp- |
Camera |
One-shot | The player’s own shot, swing or throw. |
| Tremor | comp- |
Camera |
One-shot | Shaking from no direction: a nearby explosion, a quake. |
| Impact | comp- |
Camera |
One-shot | A blow from one side: a punch, a projectile. |
| Dizzy | comp- |
Camera |
One-shot | A slow, woozy drift. |
Shared props
Section titled “Shared props”Every effect has:
| Prop | Type | Description |
|---|---|---|
amplitude |
number | Peak position offset, in world units. |
rotation |
number | Peak rotation offset, in degrees. |
One-shot effects also have:
| Prop | Type | Description |
|---|---|---|
amount |
number | The strength play() uses when you pass none, 0 to 1. |
duration |
number | Seconds the effect lasts after play(). |
Every prop is a number of zero or more. Each effect’s own defaults follow.
Breathing
Section titled “Breathing”A steady idle sway: layered waves on the vertical and side-to-side position and on the roll.
| Prop | Default | Meaning |
|---|---|---|
amplitude |
0.01 |
|
rotation |
0.02 |
|
frequency |
1 |
Breaths per second. |
Head Bob
Section titled “Head Bob”A dip on each step, and a sway and roll on each stride, while the camera walks. It measures how fast the camera actually moves over the ground, so it needs no script: slower walking bobs less, and it fades out when the camera stops. A sudden jump in position (a teleport) does not bob.
| Prop | Default | Meaning |
|---|---|---|
amplitude |
0.03 |
|
rotation |
0.4 |
|
frequency |
2.8 |
Steps per second at fullSpeed. |
fullSpeed |
4 |
The walking speed, in metres per second, at which the bob is full. |
Recoil
Section titled “Recoil”The kick of the player’s own action. The view pitches up by rotationAmplitude and moves back by amplitude, then returns over duration. It is always the same kick, never random. It is visual only: the aim does not move.
| Prop | Default |
|---|---|
amplitude |
0.02 |
rotation |
2 |
amount |
1 |
duration |
0.4 |
| Method | What it does |
|---|---|
play(amount = props. |
Kick by amount times a full kick, on top of what has not returned yet. Kicks stack up to four, so automatic fire climbs, then holds. |
stop() |
Back to rest at once. |
Tremor
Section titled “Tremor”Fast jitter on every axis, as if the ground or the air were shaking. Each play adds to the intensity, capped at 1, which then drains to nothing over duration: a punchy start that settles smoothly.
| Prop | Default | Meaning |
|---|---|---|
amplitude |
0.15 |
|
rotation |
4 |
|
frequency |
20 |
Jitter rate, in hertz. |
amount |
0.5 |
|
duration |
0.6 |
| Method | What it does |
|---|---|
play(amount = props. |
Add amount, 0 to 1, to the intensity still shaking. |
stop() |
Stop shaking at once. |
Impact
Section titled “Impact”A blow from one side. The view is pushed the way the blow travels, bounces once and settles within duration. Pushed back, it tilts up; pushed sideways, it rolls away. Blows stack.
| Prop | Default |
|---|---|
amplitude |
0.08 |
rotation |
3 |
amount |
1 |
duration |
0.5 |
| Method | What it does |
|---|---|
play(amount = props. |
A blow of amount (1 is full) travelling along direction, any { x, y, z } in world space. Without a direction, the blow comes from the front and pushes the view back. |
stop() |
Back to rest at once. |
A woozy, off-balance view: roll, pitch and yaw drift on slow waves whose rates never line up, so it never settles into a visible loop.
| Prop | Default | Meaning |
|---|---|---|
amplitude |
0.03 |
|
rotation |
3 |
|
frequency |
0.25 |
Base sway rate, in hertz. |
amount |
1 |
|
duration |
5 |
Seconds it holds. 0 holds until stop(). |
fade |
0.8 |
Seconds to fade in and out. |
| Method | What it does |
|---|---|
play(amount = props. |
Fade in to amount (0 to 1), hold for duration, then fade out. Played while already dizzy, it eases from where it is. |
stop() |
Fade out from where it is. |
Where effects run
Section titled “Where effects run”play()does nothing while the effect is disabled or its entity is inactive.- Effects run in play only, never in the editor.
- In an immersive XR session the headset replaces the view, so an XR view is never shaken.
- An idle one-shot effect and a still Head Bob cost almost nothing.
Examples
Section titled “Examples”1. Recoil on every shot
Section titled “1. Recoil on every shot”#pragma lifecycle(startup, update)
const FIRE_INTERVAL = 0.12; // seconds between shots while the button is held
let recoil;let cooldown = 0;
function startup() { recoil = self.parent.getComponent(CameraRecoilEffectComponent);}
function update(dt) { cooldown -= dt; if (Input.mouse.isButtonPressed(MouseButton.Left) && cooldown <= 0) { cooldown = FIRE_INTERVAL; recoil.play(0.5); emit('weapon/fired'); }}Holding the left mouse button fires every 0.12 seconds, and each shot kicks the view through the camera's Camera Recoil effect.
Hold the left mouse button over the view to fire and watch the view climb.
While the left button is held, the script fires every FIRE_INTERVAL seconds, counting down cooldown with the frame time dt. Each shot plays a half-strength kick. Because recoil stacks up to four kicks, the view climbs during automatic fire and then holds, which feels right for a weapon. Call recoil.play() with no argument to use the component’s own amount.
2. Explosions shake by distance
Section titled “2. Explosions shake by distance”#pragma lifecycle(startup)
const RANGE = 25; // beyond this, an explosion does not shake the view
function startup() { const cam = CameraDirector.main; if (!cam) return; const tremor = cam.getComponent(CameraTremorEffectComponent); const here = new THREE.Vector3();
// Another script emits 'bomb/exploded' with { position: { x, y, z } }. on('bomb/exploded', (data) => { cam.getWorldPosition(here); const distance = here.distanceTo(data.position); if (distance > RANGE) return; tremor.play(1 - distance / RANGE); });}Click a barrel to blow it up: the guide's ExplosionShake script plays the camera's Tremor effect, strong for the barrels near you and weaker for the far ones.
Click the nearest barrel, then the farthest one, and compare how hard the view shakes. Drag to orbit the camera, scroll to zoom.
The script measures how far the explosion is from the main camera and plays the tremor with a strength from 1 (right next to it) down to 0 (at RANGE). Each play adds to any shaking still in progress, so a chain of explosions builds up to full intensity, never beyond.
3. Poison makes the player dizzy, and the menu calms the camera
Section titled “3. Poison makes the player dizzy, and the menu calms the camera”#pragma lifecycle(startup)
function startup() { const cam = self; // on the player's camera const dizzy = cam.getComponent(CameraDizzyEffectComponent); const breathing = cam.getComponent(CameraBreathingEffectComponent); const headBob = cam.getComponent(CameraHeadBobEffectComponent);
on('player/poisoned', () => dizzy.play(0.6)); on('player/cured', () => dizzy.stop());
on('menu/open', () => { breathing.setEnabled(false); headBob.setEnabled(false); }); on('menu/close', () => { breathing.setEnabled(true); headBob.setEnabled(true); });}A first-person camera with Breathing, Head Bob and Dizzy effects: Poison and Cure play and stop the dizzy sway, and Open menu and Close menu switch the breathing and the walking bob off and on.
Walk with WASD to feel the head bob and drag to look around; press Poison to get dizzy, Cure to recover, Open menu to steady the view.
Dizzy is one-shot: play(0.6) fades in to 60% strength, holds for duration and fades out, while stop() cures it early with a fade. Breathing and Head Bob are continuous, so the script switches them off while a menu is open to keep the view steady, and back on afterwards.
Snippets
Section titled “Snippets”1. Get hit from the attacker’s direction
Section titled “1. Get hit from the attacker’s direction”#pragma lifecycle(startup)
function startup() { const cam = CameraDirector.main; if (!cam) return; const impact = cam.getComponent(CameraImpactEffectComponent); const from = new THREE.Vector3(); const to = new THREE.Vector3();
// Enemies emit 'player/hit' with { attacker: <entity id>, damage }. on('player/hit', (data) => { const attacker = findEntity(data.attacker); if (!attacker) return impact.play(1); attacker.getWorldPosition(from); cam.getWorldPosition(to); // The blow travels from the attacker towards the player. impact.play(Math.min(1, data.damage / 50), to.sub(from)); });}play(amount, direction) pushes the view the way the blow travels: from the attacker to the player, which is to - from. The direction does not need to be normalised. Heavier damage gives a stronger blow, capped at 1. Without a known attacker, a plain play(1) pushes the view back.
Common mistakes
Section titled “Common mistakes”- Disabling a one-shot effect after playing it. One-shot effects idle at no cost; leave them enabled.
play()does nothing while they are disabled. - Adding Head Bob to a third-person camera. It reacts to the camera’s own movement over the ground, which suits first person. On an orbiting camera it bobs with every zoom and orbit.
- Expecting recoil to move the aim. Recoil is visual only. Move the aim yourself if your game needs it.
- Passing the wrong impact direction. It is the direction the blow travels, from attacker to player, not the direction to the attacker.
- Testing shakes in VR. Effects never shake a headset view, to avoid discomfort.