Skip to content

ShakerComponent

Enes Kaplan edited this page Jul 9, 2024 · 1 revision

ShakerComponent

ShakerComponent is a versatile class that extends Node to provide customizable shaking functionality in Godot 4. It can be used to add shake effects to any property of any node in the scene.

Properties

Property Type Description
custom_target bool Flag to use custom targets instead of parent node
Targets Array[Node] Array of target Node objects to apply shake effect
randomize bool Flag to enable randomization of shake effect
AutoPlay bool Flag to automatically start shake effect on ready
play bool Control to start or stop the shake effect
intensity float Intensity of the shake effect (0.0 to 1.0 or greater)
duration float Duration of the shake effect (0.0 for infinite)
shake_speed float Speed of the shake effect (0.0 to 1.0 or greater)
fade_in float Fade-in easing of the shake effect
fade_out float Fade-out easing of the shake effect
shakerProperty Array[ShakerProperty] Array of ShakerProperty objects defining the shake behavior

Methods

play_shake()

Starts the shake effect.

Syntax

func play_shake() -> void

Example

var shaker = get_node("ShakerComponent")
shaker.play_shake()

Return Value

None

stop_shake()

Stops the shake effect with a fade-out.

Syntax

func stop_shake() -> void

Example

var shaker = get_node("ShakerComponent")
shaker.stop_shake()

Return Value

None

force_stop_shake()

Immediately stops the shake effect.

Syntax

func force_stop_shake() -> void

Example

var shaker = get_node("ShakerComponent")
shaker.force_stop_shake()

Return Value

None

set_progress()

Sets the shake progress.

Syntax

func set_progress(value: float) -> void
Parameter Type Description
value float The progress value to set

Example

var shaker = get_node("ShakerComponent")
shaker.set_progress(0.5)

Return Value

None

Signals

  • timeline_progress(progress: float): Emitted when the shake progress changes
  • shake_started: Emitted when the shake effect starts
  • shake_finished: Emitted when the shake effect finishes
  • shake_fading_out: Emitted when the shake effect starts fading out

Usage

To use the ShakerComponent:

  1. Add the ShakerComponent to your scene.
  2. Set the target node(s) you want to apply the shake effect to.
  3. Configure the shake properties (intensity, duration, speed, etc.).
  4. Add ShakerProperty objects to define which properties of the target node(s) should be affected and how.
  5. Call play_shake() to start the effect, or set AutoPlay to true for automatic start.

Clone this wiki locally