I am having an issue with the CharacterController.isGrounded. When my player is idle, the isGrounded is switching back and forth between true and false. The code is in the FixedUpdate function. I have looked this up and none of the other posts have solved my issue.
if (_controller.isGrounded == true)
{
_moveDirection = Vector3.zero;
_airVel = 0;
_animator.SetBool(AnimConditions.Grounded, true);
_horitzontal = Input.GetAxis(PlayerInput.Horizontal);
_vertical = Input.GetAxis(PlayerInput.Vertical);
_animator.SetFloat(AnimConditions.Direction, _horitzontal);
_animator.SetFloat(AnimConditions.Speed, _vertical);
if (Input.GetButtonDown(PlayerInput.Jump))
{
Jump();
}
}
else
{
_moveDirection.x = Input.GetAxis(PlayerInput.Horizontal) * _moveSpeed;
_moveDirection.z = Input.GetAxis(PlayerInput.Vertical) * _moveSpeed;
_moveDirection = _xForm.TransformDirection(_moveDirection);
_animator.SetBool(AnimConditions.Grounded, false);
}
_moveDirection.y -= gravity * Time.deltaTime;
_controller.Move(_moveDirection * Time.deltaTime);