Skip to content

Commit

Permalink
Reset Buffered Input Cooldown (nicholas-maltbie#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-maltbie authored Feb 22, 2023
1 parent 5170c5f commit a352396
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Packages/com.nickmaltbie.openkcc.cinemachine/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.nickmaltbie.openkcc.cinemachine",
"displayName": "OpenKCC Cinemachine",
"version": "1.3.3",
"version": "1.3.4",
"unity": "2021.1",
"unityRelease": "19f1",
"description": "Open Source Kinematic Character Controller Cinemachine extensions.",
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.nickmaltbie.openkcc.netcode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.nickmaltbie.openkcc.netcode",
"displayName": "OpenKCC Netcode",
"version": "1.3.3",
"version": "1.3.4",
"unity": "2021.1",
"unityRelease": "19f1",
"description": "Open Source Kinematic Character Controller for NetCode.",
Expand Down
1 change: 1 addition & 0 deletions Packages/com.nickmaltbie.openkcc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

## In Progress

* Small fix to `BufferedInput` to allow for resetting cooldown timer.
* Updated `KCCMovementEngine` to support layer masks for deciding what
the player can and cannot collide with.

Expand Down
13 changes: 12 additions & 1 deletion Packages/com.nickmaltbie.openkcc/OpenKCC/Input/BufferedInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public InputAction InputAction
/// <summary>
/// Is the input currently active.
/// </summary>
public bool Pressed => elapsedSinceReset > cooldown && elapsedSincePressed <= bufferTime;
public bool Pressed => elapsedSinceReset > cooldown && elapsedSincePressed < bufferTime;

/// <summary>
/// Add delta time to update the buffered input state.
Expand All @@ -103,6 +103,17 @@ public void Update()
}
}

/// <summary>
/// Reset the cooldown for this button.
/// </summary>
public void ResetCooldown()
{
if (cooldown > 0)
{
elapsedSinceReset = 0;
}
}

/// <summary>
/// Reset the active state for this button.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public void Validate_BufferedInput_Cooldown()
mockUnityService.Setup(e => e.deltaTime).Returns(1000);
bufferedInput.Update();
Assert.IsTrue(bufferedInput.Pressed);

mockUnityService.Setup(e => e.deltaTime).Returns(1000);
bufferedInput.Update();
bufferedInput.ResetCooldown();
Assert.IsFalse(bufferedInput.Pressed);
bufferedInput.Update();
Assert.IsTrue(bufferedInput.Pressed);
}
}
}
2 changes: 1 addition & 1 deletion Packages/com.nickmaltbie.openkcc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.nickmaltbie.openkcc",
"displayName": "OpenKCC",
"version": "1.3.3",
"version": "1.3.4",
"unity": "2021.1",
"unityRelease": "19f1",
"description": "Open Source Kinematic Character Controller project.",
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.3.3
bundleVersion: 1.3.4
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

0 comments on commit a352396

Please sign in to comment.