Character Controller, wrong direction

Ive made a simple 2d character controller script as shown below, moving on the y axis works fine but when moving horizontally the character always shoots up in the air, and very very slowly moves to the left and right. Any ideas whats wrong with it? thanks!

script:

// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)

// The last collision flags returned from controller.Move
private var collisionFlags : CollisionFlags;

function Update () {
var movement:Vector3;
movement = Vector3.zero ;

// Pick speed modifier
var v = Input.GetAxisRaw("Vertical");
var h = Input.GetAxisRaw("Horizontal");

movement = Vector3 (h , v, 0 ) ;
movement = transform.TransformDirection(movement);
	
// Move the controller	
var controller : CharacterController = GetComponent(CharacterController);
collisionFlags = controller.Move(movement * Time.deltaTime);

}

I tried your script, and it’s ok: the character moved up, down, right and left as expected. Maybe the problem is in your character: I once childed a cube to the character, and its collider apparently confused the character controller, making the movement very weird - it got blocked to some direction, or moved diagonally, or moved too fast. The problem only disappeared when I removed the collider.

Could it be your case? Have you childed some object to the character? If such object had a collider intersecting the character, strange things may happen.

Thanks for posting this, I had a very similar issue with my NPC’s. The ones that have models with colliders on them that I rotate to sloped surfaces were doing strange things like, running backwards, sideways and floating in the air and I couldnt work out why the heck they were doing that until I found this thread. My scripts have absolutely no code that tell them to do that and according to my scripts they were actually telling the Character controller to run forward when this strangeness was happening.

Finding out that it was caused by Colliders hitting the Character controller allowed me to create solutions that work around it. Like using OnTriggerEnter to detect the NPC’s model colliders hitting the parent object with the character controller and disabling and re-enabling the character controller when it happens to help reset it. Also disabling the child colliders while the NPC’s are running and chasing an enemy, which is when it tends to happen on sloped terrain.

So very good to know, thanks again.