I’m trying to get the player to run when I HOLD DOWN the Shift Key, not when I pressed and let go
- I introduced the shift key for running in the Action Map
- I introduced this code for it in ‘InputReader.cs’:
public bool IsSpeeding {get; private set;}
public event Action SpeedEvent;
public void OnSpeeding(InputAction.CallbackContext context)
{
if (context.performed)
{
SpeedEvent?.Invoke();
IsSpeeding = true;
}
else if (context.canceled) {
IsSpeeding = false; // boolean, indicating that this action is only done when the key mapped to this is held down
}
}
- I placed this in ‘PlayerFreeLookState.Tick()’:
if (stateMachine.InputReader.IsSpeeding)
{
stateMachine.Animator.SetFloat(FreeLookSpeedHash, 2 * movement.magnitude, AnimatorDampTime, deltaTime);
FaceMovementDirection(movement, deltaTime);
Move(movement * stateMachine.FreeLookMovementSpeed, deltaTime);
return;
}
When I click the shift, sometimes it actually returns with no issues, and sometimes it doesn’t, and it stays there, and if you click the shift key again anytime soon, there’s no guarantees we will return to the walking state
This was working perfectly last night, I have absolutely no clue why it stopped working this morning…