- Home /
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
people dont just script for you. learn to do it yourself.
I used a zombie for an example trying to explain to someone the basics of having an enemy attack, maybe this will help you.
http://answers.unity3d.com/questions/52970/creating-basic-enemy-animation-and-attacking
Answer by slkjdfv · Jul 25, 2010 at 05:33 PM
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 }
?? i'm really bad at scripting? or is that not a scrpt
it is 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 }
So do i make a new script and put only that line to it and attach it to my zombie?
you can yea or you could add it to your zombies current script. just make it a function. What the following code does is at the end of the update code it calls the function we set up. which is below the update code. :) function Update() { //your code
CheckDistance(); } function CheckDistance() { paste code i gave you here }
Yea im sorry i sound so stupid but what... i Littoraly don't know anything of how to make a script or a Function... i'm srry but i need like a whole script i can just attach to my zombie and im done... thats all
Answer by MP2fps · Dec 06, 2011 at 07:54 AM
It would probably be good just to fiddle with scripts just to know what a function is or you could even google it
Answer by 09jgriffin · Mar 17, 2012 at 01:41 PM
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
Answer by Grayson302.du · Dec 03, 2011 at 04:55 AM
does any one have a working zombie scrip. all the other ones have compiler err.
PLEASE??????????????????????
Learn to code. It takes like 4 lines for a decent Zombie attack script.
Your answer
Follow this Question
Related Questions
Zombie attack script help 1 Answer
I'm still having Trouble with this AI script 2 Answers
Creating basic enemy animation and attacking 4 Answers
Zombie Alien Mellee Attack 1 Answer
ZOMBIE AI SCRIPT 1 Answer