Enemies don't collide

Hi!
I have a question, maybe a basic question.

I have the Player with components: transform, animation, character controller and third person controller script.
And I have enemies who have the components: transform, animation, character controller and “enemy walk script”.

The “enemy walk script” makes that the enemies follow the player.

My problem is the enemies dont collide among themselves, nor anything else.
For example, I put a cube on the terrain and they don’t collide.

BUT the enemies collide against the player.

What is missing?
Thanks in advance.

3 Answers

3

You need to add a character controller to your enemy.
Here is a simple version:

    var target : Transform;  //the player
    var speed : float = 10;  // well...the speed
    var controller:CharacterController;
    function Start(){
        controller = gameObject.GetComponent(CharacterController);
    }
    function Update(){
        transform.LookAt(target);  // the NPC looks at the player
        // Here you access the Character Controller component and move your NPC with SimpleMove() giving the speed and the direction(forward).
        //As the NPC is looking at you, forward is in your direction.
        controller.SimpleMove(speed*transform.forward);
        animation.Play("Walk"); //You play the animation
      }
    }

Now your NPC has a collider and will interact with the environment just like your player.
The enemies were colliding with you because your guy got a CC.

EDIT: I saw the question got back so I updated it a little since I think it could be better than it was… I added the GetComponent function in the Start.

Thanks! Resolved. The problem was that I wasn't using Character Controller to move the enemies.

For a collision to happen, one party of the collision needs to have a rigidbody attached.

No ;) The CharacterController handles collision itself when you use Move or SimpleMove. For the physics system it acts just like a "static" collider. It can't be influenced by other physics objects and also doesn't influence other objects (beside blocking them). That's actually the advantage of the CC. It walks on it's own but can collider with other things.

With colliders, there's always trouble. I eventually fix them up but the whole process is really time wasting.

JUST USE THE RIGID BODY AND THE CHARACTER CONTROLLER ON THE SAME ENEMY AT THE SAME TIME!

Downvote because: - all caps - you don't need a rigidbody when you use a CharacterController