controller.Move will not work

For some reason, the Move command in my character controller script will not work. Here is my code:

function move () {
	var controller : CharacterController = gameObject.GetComponent(CharacterController);
	
	if (amIActive) {
		var target : Transform;
		
		if (Vector3.Distance (target.position, transform.position) <= distanceFromPlayer) {
			if (walkAnimation != "") BroadcastMessage ("returnToZero", 0);
			else inRangePlayer = true;
		}
		
		else {
			inRangePlayer = false;
			if (walkAnimation != "") BroadcastMessage (walkAnimation , 0);
			transform.rotation.x = 0;
			transform.rotation.z = 0;
			var rotation = Quaternion.LookRotation(target.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 10);
			var move = transform.TransformDirection (0, 0, speed * Time.deltaTime);
			controller.Move(move);
		}
	}
}

If I use something else instead of controller.Move, it works, but rigidbodies give me trouble. The enemy rotates towards the player, but does not move.

You may want to apply some gravity to your move vector, and move the character up some, because it may be stuck in a collider not causing it to move.

-Raiden

I did all of that, still no luck.

What value is speed. Are you sure your controller is moving more than the minimum distance.

Speed is 10, and my min distance is zero.

I broke it down to this, and had no issues, the controller moved fine.

var amIActive : boolean = true;
var target : Transform;
var speed : float = 6.5;

function Update() {
	move();
}

function move () { 
   var controller : CharacterController = gameObject.GetComponent(CharacterController); 
    
   if (amIActive) { 
      transform.rotation.x = 0; 
      transform.rotation.z = 0; 
      var rotation = Quaternion.LookRotation(target.position - transform.position); 
      transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 10); 
      var move = transform.TransformDirection (0, 0, speed * Time.deltaTime); 
      controller.Move(move); 
   } 
}

-Raiden

In case if this helps, I have kinematic rigid bodies attached to the parts of my character. (He’s made up of several meshes.)

I’ve figured out what’s causing the problem. All the sub-meshes have colliders, and that is preventing my controller from moving. The reason why I have such colliders is when my character dies, he falls into pieces. (Robot of sorts.) Any suggestions?

Yes! Instantiate is your friend, and very useful in these situations, have a prefab of your mesh with the breakaway colliders, and then swap out when your character dies.

-Raiden

It works! Oh happy day!

Thanks to all for your input.