Ai Zombie Melee Attack script.

Well i'm need my zombies to attack when when they are like right next to me. soo Is there a script i can download or copy and past to my zombie for attack cause i have very little scripting knowledge and so i can't piece together anything to make one. update The zombie already follows me and chasees me but he just doesnt attack cause i want to give him like an invisable gun the goes like 1 or 2 feet in range

All you need to do is use a raycast going from your zombie to the player and when it reaches a certain distance you tell your zombie to attack. hope this helps :)

here's a script. this may not be accurate but try hit : raycast; Physics.RayCast(transform.position,player.position,10); if (hit.distance<30) { //attack code here }

It would probably be good just to fiddle with scripts just to know what a function is or you could even google it

if you have 2 box colliders when the player hits the first collider the first collider tells the zombie to play an animation called swipe or what ever you attack animation is called, (swipe is where the zombie swings his arm and hits you) then the second collider is the one in a gameobject attached to the swinging arm the you attach the floowing script to the player.

var health = 25;

function OnCollisionEnter(object : Collision){

if(object.gameObject.tag == “Bullet”){

health–;

Debug.Log(“Enemy health” + health);

if (health <=0)

{

function OnGUI ()
GUI.Box(Rect(10,190,100,45),“u got eaten”);

}

}

}

that should work, lemme know what happenes

does any one have a working zombie scrip. all the other ones have compiler err.

PLEASE???

why don’t you try to fix em