Character movement problem, floats away

Hi guys,

I’m creating a top down game and I have a weird control problem.

Every time I press a movement key (W,A,S,D) or release a movement key, the player character moves slightly upwards away from the ground (+ve Y direction). He just floats away bit by bit.

I’ve added a Player object with a ChracterController and no rigid body.

I’ve added the following movement script:

    public class PlayerMovement : MonoBehaviour
    {
    public float Speed = 6.0f;
		
    private Vector3 _moveDirection = Vector3.zero;

	// Use this for initialization
	void Start () {
	
	}	
	// Update is called once per frame
	void Update () {

        CharacterController controller = GetComponent<CharacterController>();

	    _moveDirection = new Vector3(-1 * Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal"));
		_moveDirection *= Speed;
		
		controller.Move(_moveDirection * Time.deltaTime);				
	}
}

I’m doing camera relative movement, not character relative.

This script works fine except the unexpected Y movement on each key down and release. I’m sure I’m making a dumb noob mistake! :slight_smile:

If I use transform.Translate() this problem does not occur, but then collisions don’t work properly.

125alt text125

I suppose your CC is bumping against the ground, making it go higher step by step. You should use the other fonction of CC, SimpleMove, which does exactly what you need : 2D deplacement, y is ignored.