How to stop enemies passing through colliders

Hello all,

I’m a little stuck here. I’m using UnityScript and I have a first person controller and a few enemies with a following script and that script has them taking damage when hit with a bullet from my gun, and all that works fine, what I’m looking to find out is how to stop the enemies from going through all my colliders, the first person controller cant go through them, but all the enemies can, I’m wondering if it’s my script that allows this to happen or if it’s something else, I’ve gone through the script loads but cant find anything amiss. Thanks all.

> #pragma strict

var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var myTransform : Transform; //current transform data of this enemy
var hitPoints = 10.0;

function Awake(){
	myTransform = transform; //cache transform data for easy access/preformance
}

function Start(){
	target = GameObject.FindWithTag("Player").transform; //target the player
}

function Update () {
	myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
	Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
	
	//move towards the player
	myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

function ApplyDamage(damage : float){
	if(hitPoints <= 0.0){
		return;
	}
	
	hitPoints -= damage;
	if(hitPoints <= 0.0){
		Invoke("DelayedDetonate",0);
	}
}
function DelayedDetonate(){
	Destroy(gameObject);
}

There’s a number of ways of doing this, and I see you’ve already found one way using NavMesh, which works just fine for static scenes.

If you are looking to make more dynamic enemies you might want to take a look into SteeringBehaviors,

It sounds like what your are looking for is a combination of seek and obstacle avoidance behaviors.

There is also a great free add-on for Steering Behaviors in Unity called UnitySteer that’s very easy to just drop into your game.

http://arges-systems.com/blog/category/unitysteer/

The problem is Rigid Bodies.
Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.

This is what occurs and i need rigid bodies in script for hitting and destroying an enemy. But if you turn off the Kinematics this happens:

"If you want to use a non-convex mesh either make the Rigidbody kinematic or remove the Rigidbody component. "

So you can turn on gravity with the rigid bodies like i have done and its not solving a thing.