-
Notifications
You must be signed in to change notification settings - Fork 0
Core.Utilities.TimerOff
Dennis Steffen edited this page Jan 4, 2026
·
1 revision
The file you are looking at is TimerOff.cs. This class implements a logic pattern commonly known in industrial automation and PLC programming as a Timer Off (TOF).
The purpose of a TimerOff is to keep an output signal "True" for a specified duration after the input signal has switched from "True" to "False".
Think of it as a "shut-down delay." While the input is active, the output is active. Once the input stops, the timer starts counting down; the output only turns off once that countdown finishes.
-
Input is True: The
Outputproperty is immediately set totrue, and the internal timer (_elapsed) is reset to zero. -
Input switches to False: The timer begins to increment (using
deltaTime). -
During the delay: While the timer is counting but hasn't reached the
_delaylimit, theOutputremainstrue. -
Timer reaches Limit: Once
_elapsed>=_delay, theOutputfinally switches tofalse. -
Interruption: If the input becomes
trueagain before the timer finishes, the timer resets, and theOutputstaystruewithout ever having flickered off.
-
Coyote Time (Platformers): In a platformer, you often want to allow the player to jump for a few milliseconds even after they have walked off a ledge. You would pass "IsGrounded" as the input; the
Outputtells you if the jump is still valid. - UI Feedback/Tooltips: Preventing a tooltip from disappearing immediately when the mouse leaves an icon, allowing the user to move the mouse back in without the UI flickering.
- Combat Mechanics: Keeping a "Combo Window" active for a short duration after the last hit.
- Visual Effects: Keeping a "warning" light or highlight active for a moment after a specific event has ended.
This example allows a player to jump for 150ms after leaving a platform.
public class PlayerController
{
private TimerOff _coyoteTimer = new TimerOff(150f); // 150ms window
public void Update(float deltaTime, bool isGrounded, bool jumpButtonPressed)
{
// Update the timer based on whether we are touching the floor
_coyoteTimer.Update(isGrounded, deltaTime);
// If the output is true, we are either on the ground
// OR we just left the ground less than 150ms ago.
if (jumpButtonPressed && _coyoteTimer.Output)
{
PerformJump();
_coyoteTimer.Reset(); // Clear timer after jumping
}
}
private void PerformJump() { /* Jump logic */ }
}If you have a prompt that appears when near an object, using a TimerOff prevents the prompt from flickering if the player is right on the edge of the detection range.
public class InteractionSystem
{
private TimerOff _promptVisibilityTimer = new TimerOff(500f); // Keep visible for 0.5s
public void Update(float deltaTime, bool isWithinRange)
{
_promptVisibilityTimer.Update(isWithinRange, deltaTime);
if (_promptVisibilityTimer.Output)
{
ShowInteractionPrompt();
}
else
{
HideInteractionPrompt();
}
}
private void ShowInteractionPrompt() { /* UI Logic */ }
private void HideInteractionPrompt() { /* UI Logic */ }
}-
Output: The current state (True if input is high OR if the delay is still running). -
TimeRemaining: Useful for UI progress bars (e.g., showing how much "Coyote Time" or "Combo Time" is left). -
Elapsed: How many milliseconds have passed since the input wentfalse.