UGTK / Toolkit / Ui Module / Camera Shake System Completed
Camera Shake
Summary
The Camera Shake module applies Perlin-noise position and rotation shake to a target Transform. It supports layered simultaneous shakes, reusable ShakeProfiles, envelopes, and per-shake handles for stopping and completion callbacks.
Content
Modules Dependencies
This module has no hard UGTK dependencies.
Setup
Drop the CameraShake prefab into the scene (or add Mn_CameraShake straight onto your camera):
How To Use
- Add
Mn_CameraShaketo your camera (or any object). Iftargetis left empty it auto-assignsCamera.main.transformon Start. - Trigger a shake:
- From an Inspector/UnityEvent with no arguments:
TriggerDefaultShake(). - Quick one-shot from code:
PlaySimpleShake(duration, intensity, frequency, ...). - From a predefined profile:
PlayShake(profile, strengthMultiplier, durationOverride, tag, onComplete). - Reference the returned
ShakeHandletoStopShake(handle)/StopShakeById(id), or callStopAllShakes(). - Access it anywhere via the static
Mn_CameraShake.Instance, and hookOnAnyShakeCompletedto react when any shake ends.
Each ShakeProfile exposes duration, intensity, per-axis position/rotation amplitude and masks, frequency, an envelope curve, unscaled-time option, local/world space, and extra blend-in/out.
Good to know:
- The base transform is re-read every frame. In
LateUpdatethe component samples the target's current position/rotation before applying the offsets, so it composes correctly with a follow camera or Cinemachine. The flip side: any script that writes the camera transform in a laterLateUpdatewipes the shake — fix it with Script Execution Order, not with more intensity. Instanceis a lazyFindFirstObjectByType, not a persistent singleton. It is notDontDestroyOnLoad, and when nothing is found it logs a warning and returns null instead of creating one: put a shaker in every scene that needs it, and null-check before calling.- Shakes are additive. Two simultaneous shakes sum their offsets, so an explosion plus a hit can
overshoot badly. Use
strengthMultiplier, or stop the running one before starting the big one. - A null target warns once and does nothing — no exception, no silent failure: check the console if a shake seems to have no effect.
- Set
unscaledTimeon the profile to keep shaking while the game is paused (Time.timeScale = 0).
Testing Scene
Open Debug/CameraShakeScene.unity. It holds a CameraShake object wired to the Main Camera,
an orange landmark and a floor, so a shake is something you can actually see. Select CameraShake
and use the Editor Test Tools block; the controls need Play mode, and outside it they say so.
What to do, in order:
- Press Trigger Default Shake() and watch the landmark move against the frame.
- Raise Intensity and press Play Simple Shake(): the same shake, harder.
- Turn Affect Rotation off and repeat. A shake that only translates reads as a bump; one that rotates reads as an impact.
- Start a second shake while the first is running. They add up rather than replacing each other, which is what makes a burst of small hits feel different from one big one.
- Press StopAllShakes() while several are running: the camera returns to its base transform, not to wherever the last frame left it.
The scene shipped with nothing but a camera and a light: the component that gives the module its name was in a prefab that no scene used, so there was nothing to shake and nothing to look at.
Technical Info
- Mn_CameraShake: singleton-style manager that updates all active shakes in
LateUpdate, accumulates their Perlin offsets and applies them from the frame's base transform. - ShakeProfile: serializable configuration for a single shake's motion and timing.
- ShakeHandle / ShakeInstance: handle returned to callers and the internal runtime state (seeds, elapsed time, completion callback) of a live shake.
© 2026 Marcello De Bonis. All rights reserved
UGTKengine within an engine


