Character Controller Script Increasing characters Y position

Hello all!

I am having an issue with my character controller script. It is working perfectly except for one issue. Whatever object I attach it to has its Y position increased by 8 at runtime. Essentially, my Idlestate script updates myVector and then my player controller script runs myController.Move(myVector).

I have a variable for velocity which I set myVector.y = to. This is my first time posting a question and I apologize if the formatting is off. Any help would be much appreciated!

public class PlayerController : MonoBehaviour

    // Create an instance of the statemachine
    public HStateMachine stateMachine = new HStateMachine();

     // Start is called before the first frame update
    void Start()
        // Start the state off in the Idle State
        stateMachine.ChangeState(new HIdleState(this));
        // Reference to the animator
        anim = GetComponent < Animator>();

    // Character Controller reference
    public CharacterController myController;

    // Camera reference
    // A transform is a reference to somethings position, rotation, and scale.
    public Transform cameraTransform;

    // Animator reference
    public Animator anim;

    // Bool used to tell which direction the player is facing
    public bool facingRight = false;

    // Player movement Speed
    public float speed = 3f;

    // Player Jump speed
    public float jumpSpeed = 10f;

    // Gravity affecting Player
    public float gravityStrength = 5f;

    // If player is on the ground they are able to jump
    public bool canJump = false;

    // Create a vertical velocity to use for implementing gravity and jumping.
    public float verticalVelocity;

    // Player's Vector
    public Vector3 myVector;

    // Collision Flags to detect if the player is grounded
    public CollisionFlags flags;

    // Update is called once per frame
    void Update()
        // Run the State Machine and handle the current state.

        // Flip the player's sprite by rotating the x value 180 degrees
        if ( (myVector.x < 0 && facingRight) || (myVector.x > 0 && !facingRight) )
            facingRight = !facingRight;
            transform.Rotate(new Vector3(0, 180, 0));


        //myVector.y = verticalVelocity * Time.deltaTime; // add the new vertical velocity to player to simulate gravity.

        // Use Input to move the character
        // Move the character Controller and store the reference in a collision flag. Velocity along the y-axis is ignored. Gravity is automatically applied.
        flags = myController.Move(myVector);




Idle state script:

public class HIdleState : HPlayerState
    // Reference Player Controller
    PlayerController playerController;

    public HIdleState(PlayerController playerController)
        // Point to the PlayerController passed in.
        this.playerController = playerController;
    public override void Enter()
        Debug.Log("entering Idle state");
    public override void Execute()
        // Debug.Log("updating Idle state");

        // Vector3 for the Player.
        playerController.myVector = new Vector3(0, 0, 0);

        // Get Input from the player
        playerController.myVector.x = Input.GetAxisRaw("Horizontal");
        playerController.myVector.z = Input.GetAxisRaw("Vertical");
        playerController.myVector = Vector3.ClampMagnitude(playerController.myVector, 1f);

        // Add speed to the player.
        // Multipling something by time.deltatime converts it from moving an amount per frame to an amount per second.
        playerController.myVector = playerController.myVector * playerController.speed * Time.deltaTime;

        // Animate the player if they are walking and grounded.
        if ((Math.Abs(playerController.myVector.x) > 0 && playerController.canJump) || (Math.Abs(playerController.myVector.z) > 0 && playerController.canJump))
            playerController.anim.SetBool("Walking", true);
            playerController.anim.SetBool("Walking", false);

        // Check the collision on CharacterController.Move to know if the player is grounded.
        if ((playerController.flags & CollisionFlags.Below) != 0)
            // The player is grounded so set jumping bool in the animator to false.
            playerController.anim.SetBool("Jumping", false); 
            playerController.canJump = true;
            playerController.verticalVelocity = -3f;
             playerController.canJump = false;

        // Add new speed to old speed for acceleration on the vertical velocity.
        playerController.verticalVelocity = playerController.verticalVelocity - (playerController.gravityStrength * Time.deltaTime);

        // If the Jump button is pressed change to the Airborne State.
        if (Input.GetButtonDown("Jump"))
            if (playerController.canJump == true)
                playerController.stateMachine.ChangeState(new HAirborneState(playerController));
        // Set the player's y vector to verticalVelocity to know how much to move.
        playerController.myVector.y = playerController.verticalVelocity * Time.deltaTime;


    public override void Exit()
        Debug.Log("exiting Idle state");


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.