Aego Русский

Camera Shake 2D

Tunes the shake of its virtual camera. Shake grows with trauma and fades over time.

component camera.CameraShake2D
On this page

Usage

Needs Virtual Camera 2D on the same node.

Try it

Rotate the shaken view

A single full hit is held with zero Decay. The landmarks stay still; the camera's zero Max Angle initially prevents rotation.

Change Max Angle from 0 to 0.5 radians to see the view shake. Reset restores the still view. Reduced-motion settings can suppress shake.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene6 nodes
Camera
Transform
position[0, 0]rotation0scale[1, 1]
View
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Ground
Transform
position[0, 3]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#374151ffsizeVec2[30, 1]
Left post
Transform
position[-5, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#3b82f6ffsizeVec2[1, 4]
Right post
Transform
position[5, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#22c55effsizeVec2[1, 4]
Landmark
Transform
position[0, -1]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#f59e0bffsizeVec2[2, 2]
Scriptmain.aes
package demo

import "aego/camera"

// Hold one full hit so the editable Max Angle can be compared at any time.
// Zero Decay in the scene keeps the hit; the camera service supplies the motion.
script ShakeOnce {
    func Ready() {
        camera.Shake(1)
    }
}

Fields

NameTypeDefaultDescription
Decayfloat1.5

Trauma lost per second.

≥ 0
Max OffsetVec2(0.5, 0.5)

Largest offset in world units at full trauma.

Max Anglefloat0.05

Largest rotation in radians at full trauma.

≥ 0
Frequencyfloat25

How fast the shake changes, in noise steps per second.

≥ 0
Exponentfloat2

Shake is trauma to this power: 2 keeps small hits subtle.

≥ 1

Methods

Add method

func (CameraShake2D) Add(trauma float)

Adds trauma to the output of this camera; trauma is capped at 1.