Skip to content

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.

  • 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.
  • Continuous effects run while they are enabled: Breathing and Head Bob. Switch them with setEnabled(true) or setEnabled(false).
  • One-shot effects stay enabled and idle, at no cost, until a script calls play(): Recoil, Tremor, Impact and Dizzy. Calling play() 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-breathing CameraBreathingEffectComponent Continuous A gentle idle sway, like a handheld camera.
Head Bob comp-camera-head-bob CameraHeadBobEffectComponent Continuous A step bounce while a first-person camera walks.
Recoil comp-camera-recoil CameraRecoilEffectComponent One-shot The player’s own shot, swing or throw.
Tremor comp-camera-tremor CameraTremorEffectComponent One-shot Shaking from no direction: a nearby explosion, a quake.
Impact comp-camera-impact CameraImpactEffectComponent One-shot A blow from one side: a punch, a projectile.
Dizzy comp-camera-dizzy CameraDizzyEffectComponent One-shot A slow, woozy drift.

Every effect has:

Prop Type Description
amplitude number Peak position offset, in world units.
rotationAmplitude 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.

A steady idle sway: layered waves on the vertical and side-to-side position and on the roll.

Prop Default Meaning
amplitude 0.01
rotationAmplitude 0.02
frequency 1 Breaths per second.

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
rotationAmplitude 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.

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
rotationAmplitude 2
amount 1
duration 0.4
Method What it does
play(amount = props.amount) 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.

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
rotationAmplitude 4
frequency 20 Jitter rate, in hertz.
amount 0.5
duration 0.6
Method What it does
play(amount = props.amount) Add amount, 0 to 1, to the intensity still shaking.
stop() Stop shaking at once.

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
rotationAmplitude 3
amount 1
duration 0.5
Method What it does
play(amount = props.amount, direction?) 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
rotationAmplitude 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.amount) 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.
  • 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.
Gun.jx
#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');
}
}

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.

ExplosionShake.jx
#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);
});
}

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”
StatusEffects.jx
#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);
});
}

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.

1. Get hit from the attacker’s direction

Section titled “1. Get hit from the attacker’s direction”
HitReaction.jx
#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.

  • 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.