Skip to main content

ShakeDetector

A class in Root.Township, the global namespace.

Component that fires an event when its rigidbody is shaken back and forth hard enough. Wraps a ShakeDetectorHelper checked every fixed update.

Constructors​

MemberWhat it is
ShakeDetector()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

6 private and internal fields
MemberWhat it is
private float fadePerSecondHow fast built-up shake strength fades away.
private ShakeDetectorHelper helperThe ShakeDetectorHelper doing the work.
private float jumpPerChangeStrength added for a full reversal of direction.
private AltaEvent shakenBacking field for Shaken.
private float thresholdStrength needed to count as a shake.
private float velocityThresholdSpeed the rigidbody must reach before a direction change counts. Squared before it is passed to the helper.

Properties​

MemberWhat it is
AltaEvent Shaken { get; }Inspector event fired each time the shake strength goes over threshold.
float Strength { get; }Current shake build-up from the helper. Resets to 0 when a shake fires.

Methods​

2 private and internal methods
MemberWhat it is
private void Awake()Makes the helper from the inspector values and this object's rigidbody, and links its shake event to shaken.
private void FixedUpdate()Runs the helper's shake check.

Used in​

Members of other types that take, return or hold a ShakeDetector: