Right now I am just testing some conditions to see if I can get it to work and it does partially.
If my player velocity.x or velocity.z >= 1.0f and the raycast does not touch the ground, that means that my player is slightly moving despite not being grounded, so I “reset” the W/A/S/D + space bar input keys to stop the movement. It works but once my player falls back down to the ground or stops moving and stands idle, I cannot move until I release and then re-press the key(s).
I am trying to change the reset so that it is temporary. So if those conditions above are met, my input keys are all reset and then my player stops moving (whether that means they fall, go from run->idle, etc), but after a certain amount of time such as 0.5f, even if my keys are still being held down the entire time, the player will start moving again since the 0.5f delay/timer is up.
I am using a character controller with default controller code, and after my controller.Move(velocity * Time) line I add CheckForMinimalMovement(move); underneath.
private bool inputResetFlag = false;
private int framesToIgnoreInput = 5;
private int framesSinceReset = 0;
void Update()
{
if (!inputResetFlag)
{
ProcessInput();
}
else
{
framesSinceReset++;
if (framesSinceReset >= framesToIgnoreInput)
{
framesSinceReset = 0;
inputResetFlag = false;
}
}
...
controller.Move(velocity * Time.deltaTime);
CheckForMinimalMovement(move);
}
void ProcessInput()
{
CheckKeyCombo(KeyCode.A); // check hte keys that are being pressed, not sure of a better way
CheckKeyCombo(KeyCode.B);
CheckKeyCombo(KeyCode.C);
CheckKeyCombo(KeyCode.D);
}
void CheckKeyCombo(KeyCode key)
{
bool keyPressed = Input.GetKey(key);
bool spacePressed = Input.GetKey(KeyCode.Space);
}
void CheckForMinimalMovement(Vector3 velocity)
{
if (velocity != Vector3.zero)
{
if (Mathf.Abs(velocity.x) >= 1.0f || Mathf.Abs(velocity.z) >= 1.0f)
{
RaycastHit downHit;
if (Physics.Raycast(transform.position, -transform.up, out downHit, 1.1f))
{
}
else
{
resetCounter++; // just to see explicitly how many times the key input reset is working
Input.ResetInputAxes();
ResetPlayerInput();
return;
}
}
}
}