Y position increasing on character controller

Hello all. I’ve run into a weird issue when moving the character controller in local space. I’m rotating an object around a sphere using joystick inputs. The object is the child of the sphere, and movement is happening in local space. The issue I run into is that the radius on which the object rotates slowly increases as it moves. Can’t for the life of me figure out why. So, for example, if the object starts touching the outside of the sphere, after several rotations it’s moved away from the surface. Any recommendations on how to limit this would be appreciated.

public class Movement : MonoBehaviour
    public float speed = 4;
    Vector3 movement;

    Vector3 up;
    public Transform planet;

    CharacterController controller;

    void Start()
        controller = GetComponent<CharacterController>();

    void Update()
        movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized * speed;

        //Translate movement from world to local space
        movement = transform.TransformDirection(movement);


        //Rotate so that up is always away from center
        up = transform.position - planet.position;
        transform.rotation = Quaternion.FromToRotation(transform.up, up) * transform.rotation;

My Unity is adding 0.13 to the Y axis when I move my character too.
I can’t figure out why, so, at the end of my moviment, a zero my Y again:

transform.position = new Vector3(transform.position.x, 0, transform.position.z);

Not the best solution but it’s what I can do for now…

I had the same problem and found your unanswered post. After a lot of research I came across this video which was very helpful.

Basically my problem was the setting in the character controller for "skin width". This is a buffer area around the the collision capsule that will trigger a collision with things such as the ground, Mine was set too high for the scale of my world and thus noticeable raised my character off the ground. It should be set to some ratio of the controller capsule "radius" setting. The recommendation was 10% but had a radius of 0.05 and set siskin width to .001 which seemed to fix my issue.

Hope this helps some one in the future.