I’m trying to prevent the player to start sprinting while in air, to accomplish this I need to get when I start to press the left shift, but the GetKeyDown for “justSprinted” always returns false (everything else works as intended), so the “airSprintCheck” (that prevent the player to sprint) never goes true.
As you can see everything seems ok.
I also tried in the Update function but nothing changed.
float hMove = Input.GetAxisRaw("Horizontal"); //move
float vMove = Input.GetAxisRaw("Vertical");
bool jump = Input.GetKeyDown(KeyCode.Space); //jump
bool isGrounded = Physics.Raycast(groundDetector.position, Vector3.down, 0.1f, ground);
bool isJumping = jump && isGrounded;
bool sprint = Input.GetKey(KeyCode.LeftShift); //sprint
bool justSprinted = Input.GetKeyDown(KeyCode.LeftShift);
bool isSprinting = sprint && vMove > 0;
bool slide = Input.GetKey(KeyCode.LeftControl); //slide
bool isSliding = isSprinting && slide && !sliding;
if (justSprinted && !isGrounded)
{
airSprintCheck = true;
}
else if (isGrounded)
{
airSprintCheck = false;
}
Vector3 direction = Vector3.zero;
float trueSpeed = speed;
if (!sliding)
{
direction = new Vector3(hMove, 0, vMove).normalized;
direction = transform.TransformDirection(direction);
if (isSprinting && !airSprintCheck)
{
if (crouched)
SetCrouch(false);
trueSpeed *= sprintModifier;
}
else if (crouched)
{
trueSpeed *= crouchModifier;
}
}
