I encountered a problem in Unity related to the Character Controller, namely with checking whether the player is on the ground or not (isGrounded).
A player walking down a slope with a minimum angle of deflection is considered to be in the air, while the physics of the character attracts him to the ground.
I would like to detect that a character descending a slope is still touching the ground.
Is it possible to solve this problem using standard tools to update the surface under the player, or will I have to make a system of checking this myself using SphereCast or something similar?
private void HandleMovementAndJump() { IsGrounded = characterController.isGrounded; MoveVector = !inputState.MoveIsLocked ? InputManager.MoveInput : Vector2.zero; IsSprinting = !inputState.MoveIsLocked && staminaSystem.currentStamina > 0 &&[![enter image description here][1]][1] InputManager.SprintInput != 0 && MoveVector.y > 0f && CurrentState != FSMState.Crouch; CurrentInputVector = Vector2.SmoothDamp(CurrentInputVector, MoveVector, ref smoothInputVelocity, smoothInputSpeed); CurrentInputVectorInt = new Vector2(Mathf.Round(CurrentInputVector.x), Mathf.Round(CurrentInputVector.y)); if (CurrentInputVectorInt != Vector2.zero) { CurrentState = IsSprinting ? FSMState.Run : FSMState.Move; } else { CurrentState = FSMState.Idle; } Vector3 rightMove = transform.right * CurrentInputVector.x; Vector3 forwardMove = transform.forward * CurrentInputVector.y; float speed = GetCurrentSpeedValue(); CurrentMovementSpeed = Mathf.Lerp(CurrentMovementSpeed, speed, Time.deltaTime * smoothChangeSpeedValue); Vector3 movementVector = Vector3.ClampMagnitude(rightMove + forwardMove, 1f) * CurrentMovementSpeed; if (IsGrounded) { moveDirection = movementVector; } else { Vector3 airControl = movementVector * airControlFactor; moveDirection = new Vector3( moveDirection.x + airControl.x * Time.deltaTime, moveDirection.y, moveDirection.z + airControl.z * Time.deltaTime); } playerVelocity.y = IsGrounded && playerVelocity.y < 0 ? 0f : playerVelocity.y; if (!inputState.MoveIsLocked) { if (staminaSystem.currentStamina >= 25 && InputManager.JumpInput && IsGrounded && !IsCrouching) { CurrentState = FSMState.Jump; playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * playerGravity); //staminaSystem.LostStamina(10f); } } if (!IsGrounded) { CurrentState = FSMState.Fall; } playerVelocity.y += playerGravity * Time.deltaTime; if (characterController.collisionFlags == CollisionFlags.Above && playerVelocity.y > 0) { playerVelocity.y = 0f; } UpdateSlopeSliding(); characterController.Move((moveDirection + playerVelocity) * Time.deltaTime); } 