character controller randomly flies up

Ok so I've got a topdown camera, and a sphere with character controller component and this script attached to the sphere:

    var speed = 5.0;

function Update () {
var controller : CharacterController = GetComponent(CharacterController) ;
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
var vec = new Vector3(x,0,z);

controller.Move(vec);

}

The sphere is on a flat plane, and theres some static cubes attached to all sides (walls).. at first I thought this happened every time I bumped the sphere into something, but after playing around I realized it's not upon bumping, but upon going backwards (i.e. the direction the sphere is NOT pointing), what happens is that it flies upwards towards the screen. I really dont see how where it's facing can affect its Y access movement as the code clearly only alters the X and Z axis

any idea what's causing this?

extra info: all walls have mesh colliders Tried this again with a cube, it took longer to happen (where with the sphere it happend instantly when i moved backward, with the cube i had to move around alot before i noticed it elevated) There is a script attached the camera that forces the sphere to look at the mouse pointer (surely this is irrelevant when the move script ignores the sphere's direction)

Update: Now i realize that it's not when moving back only, but also right, not sure what this means exactly.

Check your character controller's gameobject's children for any rogue colliders. It sounds like you might have created a sphere gameobject (gameobject->create other->sphere, which comes with a sphere collider attached) and then attached that to your character controller.

What then happens is your character controller bumps into those rogue colliders, causing it to try to climb over itself... which could explain your Y axis jumps.

You can alternately test this theory out by changing the Step Offset in the Character Controller to 0 and that might fix your jumps as well.

Whilst I'm not sure why your controller was heading skyward (y axis)... the problem you have is this:

controller.Move()

I don't know the innards of the Move() function, but basically it seems to be expecting a 'world space' transform vector. So all you need to do is convert the Input.GetAxis() vectors from local to world space like this:

var speed = 5.0;

function Update () {
    var controller : CharacterController = GetComponent(CharacterController) ;
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
    var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
    var vec = new transform.TransformDirection(Vector3(x,0,z));

    controller.Move(vec);
}

http://unity3d.com/support/documentation/ScriptReference/Transform.TransformDirection.html

flyhax.

/thread