I remember when I had a problem with the player’s gravity, I fixed that, but now I am having a problem with the fact that even though the player is on the ground, they are alternating from grounded to not grounded.
_moveSpeed = 5f;
_gravity = 9.81f;
_jumpSpeed = 4f;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontalInput, 0, verticalInput);
if (_controller.isGrounded)
{
if(Input.GetButtonDown("Jump"))
{
audioSource.PlayOneShot(JumpSound, 1);
_directionY = _jumpSpeed;
}
}
if (!_controller.isGrounded)
{
_directionY -= _gravity * Time.deltaTime;
direction.y = _directionY;
}
_controller.Move(direction * _moveSpeed * Time.deltaTime);
animator.SetBool("isWalking", verticalInput != 0 || horizontalInput != 0);
animator.SetBool("isGrounded", _controller.isGrounded == true);
animator.SetBool("Swimming", movemode == 1);
I also made it so that if the player touches the ground, it sets “_directionY” to 0.
if (other.gameObject.tag == "Ground")
{
_directionY = 0;
}
So what is the problem? Can someone help me fix it?