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
| Member | What 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
| Member | What it is |
|---|
private float fadePerSecond | How much Strength drops per second. |
private float jumpPerChange | Strength added for a full reversal of direction (scaled by how opposite the new direction is). |
private Vector3 oldDirection | Velocity direction from the last check, compared with the current one. |
private Rigidbody targetRigidBody | The rigidbody whose velocity is watched. |
private float threshold | Strength at which Shaken fires. Zero or less turns firing off. |
private float velocityThresholdSquared | Squared speed below which movement is ignored. |
Properties
| Member | What it is |
|---|
float Strength { get; private set; } | Current shake strength. Grows with each direction reversal and fades over time. |
Events
| Member | What it is |
|---|
event Action Shaken | Raised when Strength passes the threshold. The handler must be set, as it is called without a null check. |
Methods
| Member | What 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: