Forum rules - please read before posting.

Character controller floats/bounces down slopes

Due to complications with a rigidbody setup (Freeze on idle just doesn't work for some reason), I've opted for a character controller. However, no matter what I do, it always has trouble with going down slopes.

If the "simulated mass" is too low, closer to 1, the player will float away with a soft descent until stopping and dropping straight down. If the mass is really high, such as 100, it "bounces" down the slope.

Is there a way for the character controller to just slide down slopes at their respective angles to avoid this? I'm not planning on making use of physics but need some vertical movement.

Comments

  • This is a common issue with Unity's Character Controller, and isn't strictly an AC-related issue.

    However, the "First Person Player prefab" package over on the Downloads page includes a script - StickToSlope.cs - to remedy this behaviour. Though it's intended for first-person players, it should also work on third-person characters as well.

  • That seems to have fixed it. Had to lower the mass and extend the ray, but it basically works fine. Thanks!

  • Sorry to bring this thread back, but I can't seem to find the StickToSlope.cs script mentioned in the First Person Player prefab package. Does anyone have a copy of it?

  • Here is the script for you to copy and save:

    using UnityEngine;
    
    namespace AC
    {
    
        [RequireComponent (typeof (AC.Char))]
        public class StickToSlope : MonoBehaviour
        {
    
            [SerializeField] [Range (0f, 1f)] private float rayLength = 0.2f;
            private AC.Char character;
            private CharacterController characterController;
    
            private void Awake ()
            {
                character = GetComponent<AC.Char> ();
                characterController = GetComponent<CharacterController> ();
            }
    
            private void Update ()
            {
                if (!character.IsJumping)
                {
                    RaycastHit raycastHit = new RaycastHit ();
                    if (Physics.Raycast (transform.position + Vector3.up, -Vector3.up, out raycastHit, 1f + rayLength))
                    {
                        float distance = raycastHit.distance - 1f;
                        characterController.Move (-Vector3.up * distance);
                    }
                }
            }
    
        }
    
    }
    
  • Thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.