Appearance
Kiln API / kiln / CameraRigState
Class: CameraRigState
The camera rig's settings and state. Change settings with res.mut(CameraRig): offset from the focus point (3D default 0, 10, 12; 2D 0, 0, 100), smoothing (catch-up rate per second; 0 snaps), lookAt (3D: aim at the focus), bounds (clamp the focus), zoom, and shake tuning (maxOffset world units, maxAngle radians, decay trauma per second). shake(amount) adds trauma 0..1; the shake is trauma² so small hits stay subtle. focus is where the rig looks now.
Constructors
Constructor
ts
new CameraRigState(is2D): CameraRigState;Parameters
| Parameter | Type |
|---|---|
is2D | boolean |
Returns
CameraRigState
Properties
enabled
ts
enabled: boolean = true;offset
ts
offset: Vec;smoothing
ts
smoothing: number = 6;lookAt
ts
lookAt: boolean = true;bounds
ts
bounds: CameraBounds | null = null;zoom
ts
zoom: number = 1;trauma
ts
trauma: number = 0;maxOffset
ts
maxOffset: number;maxAngle
ts
maxAngle: number = 0.06;decay
ts
decay: number = 1.5;frequency
ts
frequency: number = 18;Noise speed of the shake, in cycles per second.
focus
ts
focus: Vec;The smoothed point the camera follows. Set it to cut the camera somewhere.
started
ts
started: boolean = false;False until the first target is found; then the rig snaps to it once.
t
ts
t: number = 0;Seconds of shake noise elapsed.
current
ts
readonly current: object;The current shake offset and roll, for tests and for effects that want to match it.
x
ts
x: number = 0;y
ts
y: number = 0;z
ts
z: number = 0;roll
ts
roll: number = 0;is2D
ts
readonly is2D: boolean;Methods
shake()
ts
shake(amount): void;Adds trauma (0..1 total). 0.2 is a bump, 0.5 a hit, 1 an explosion.
Parameters
| Parameter | Type |
|---|---|
amount | number |
Returns
void
snap()
ts
snap(to?): void;Jumps to the target (or to) next frame instead of easing there.
Parameters
| Parameter | Type |
|---|---|
to? | Partial<Vec> |
Returns
void
toJSON()
ts
toJSON(): object;Returns
object
enabled
ts
enabled: boolean;offset
ts
offset: Vec;smoothing
ts
smoothing: number;lookAt
ts
lookAt: boolean;bounds
ts
bounds: CameraBounds | null;zoom
ts
zoom: number;trauma
ts
trauma: number;focus
ts
focus: Vec;restore()
ts
restore(json): void;Parameters
| Parameter | Type |
|---|---|
json | Partial<ReturnType<CameraRigState["toJSON"]>> |
Returns
void