Hello, newbie here, I have a quick question, why does the character animation work so strangely? When I jump the animation keeps switching between jump and idle and the same when landing. From what I checked on the internet I seem to have given a good condition to check if the character is falling.
private bool CheckGrounded()
{
isGrounded = boxCollider.IsTouchingLayers(LayerMask.GetMask("Ground"));
return isGrounded;
}
private void CheckIfFalling()
{
float verticalVelocity = rb.linearVelocity.y;
bool isMovingDown = verticalVelocity < -0.1f;
if (!isGrounded && isMovingDown)
{
animator.SetBool("isFalling", true);
}
else if (isGrounded)
{
animator.SetBool("isFalling", false);
}
}
private void OnJump(InputValue _inputValue)
{
if (_inputValue.isPressed && playerController.isGrounded)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
animator.SetBool("isGrounded", true);
}
}