Skip to main content

ShakeDetectorHelper

A class in Root.Township, the global namespace.

Plain helper that tracks how hard a rigidbody is being shaken back and forth and fires an event past a threshold. Made by ShakeDetector, ShakeDetectorFactory and ShakeInput, which call CalculateShake each frame.

Constructors​

MemberWhat it is
ShakeDetectorHelper(float velocityThresholdSquared, float threshold, float fadePerSecond, float jumpPerChange, Rigidbody targetRigidBody)Creates a ShakeDetectorHelper from velocityThresholdSquared, threshold, fadePerSecond, jumpPerChange and targetRigidBody.

Fields​

6 private and internal fields
MemberWhat it is
private float fadePerSecondHow much Strength drops per second.
private float jumpPerChangeStrength added for a full reversal of direction (scaled by how opposite the new direction is).
private Vector3 oldDirectionVelocity direction from the last check, compared with the current one.
private Rigidbody targetRigidBodyThe rigidbody whose velocity is watched.
private float thresholdStrength at which Shaken fires. Zero or less turns firing off.
private float velocityThresholdSquaredSquared speed below which movement is ignored.

Properties​

MemberWhat it is
float Strength { get; private set; }Current shake strength. Grows with each direction reversal and fades over time.

Events​

MemberWhat it is
event Action ShakenRaised when Strength passes the threshold. The handler must be set, as it is called without a null check.

Methods​

MemberWhat it is
void CalculateShake()Fades Strength, then adds to it when the velocity reverses direction; raises Shaken and resets once it passes threshold.

Used in​

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