Broken zombie AI; enemy is flying

Hi. I created AI like this:

void FixedUpdate()
	{
		if (Vector3.Distance (transform.position,target.transform.position) < 30 || immaAtacked == true)
			{
			animation.Stop("stand");
			immaAtacked = true;
			animation.Play ("walk");
			myRigidbody.AddForce(myTransform.forward * movementSpeed * Time.deltaTime);
		}
	}
}

I’ve got capsule collider on it, rigidbody with frozen Y position and rotation, gravity with mass on rigidbody. Still its moving through the walls. The problem is follow script too. Opponent goes one way, goes straight to the hero, but when it touches the character it still going in the same direction. I have no idea how to modificate my script. I tried also:

myTransform.rigidbody.velocity += myTransform.forward * movementSpeed * Time.deltaTime;
myTransform.position += myTransform.forward * movementSpeed * Time.deltaTime;

but it doesn’t work too. Please help me.

When you add force to a rigid body is does just that. It’s like pressing a ball, it wont necessarily stop when you stop pushing on it. To make him stop you may want to set his force to 0.

//Stops the character and prevents him from rotating.
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;

Would cause him to stop, just place it inside of your hit detection code. If you want the zombie to continue to look at the player simply remove the second line.

As for your zombie going through the walls, there’s countless reasons why. Please check to make sure the walls have a collider, probably a box collider that’s enabled. You may also want to change the collision detection on your zombie to continuous dynamic.

Still problem is a move. Opponent charge at me and when I dodge that zombie is moving forward like on ace. When enemy slow down it accelerate to me again etc. I’m thinking about code that you give. If I use it like U said my enemy isn’t moving. Maybe something like this:

if (distance < 10)//if enemy attacking me and its for first time,
{
focus = true;//set focus on true
}

if (distance> 10  focus = true)//if distance is growing and its after first attack
{
rigidbody.velocity = Vector3.zero;//slow down and let charge again
}

but I think its not smart to write something like that. Any idea?

And about collision - it doesn’t work. I thought that it work but nope, it isn’t. Box colliders on cubes, capsule collider on model, continous dynamic collision detect on rigidbody.