Wednesday, December 25, 2024
spot_img

unity – Character Controller isGrounded reviews false when descending slopes


I encountered an issue in Unity associated to the Character Controller, specifically with checking whether or not the participant is on the bottom or not (isGrounded).

A participant strolling down a slope with a minimal angle of deflection is taken into account to be within the air, whereas the physics of the character attracts him to the bottom.

I wish to detect {that a} character descending a slope remains to be touching the bottom.

Is it doable to unravel this drawback utilizing normal instruments to replace the floor below the participant, or will I’ve to make a system of checking this myself utilizing SphereCast or one thing comparable?

personal 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.Spherical(CurrentInputVector.x), Mathf.Spherical(CurrentInputVector.y));

    if (CurrentInputVectorInt != Vector2.zero)
    {
        CurrentState = IsSprinting ? FSMState.Run : FSMState.Transfer;
    }
    else
    {
        CurrentState = FSMState.Idle;
    }

    Vector3 rightMove = rework.proper * CurrentInputVector.x;
    Vector3 forwardMove = rework.ahead * CurrentInputVector.y;

    float velocity = GetCurrentSpeedValue();
    CurrentMovementSpeed = Mathf.Lerp(CurrentMovementSpeed, velocity, 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 = 25 &&
            InputManager.JumpInput &&
            IsGrounded &&
            !IsCrouching)
        {
            CurrentState = FSMState.Leap;
            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.Transfer((moveDirection + playerVelocity) * Time.deltaTime);
}

Character Controller

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles