- Home /
looking to make for a zombie script AI,navmesh or not?
Hi i m looking to make a simple zombie script AI. The enemy should follow "player" and when the distance of player and enemy is near, this attack changing the animation
To make a good zombie script i need a navmesh agent or not? can you help me with a simple start code?
i would suggest against navmesh as zombies are not expected to be smart. and a zombie that can make its way through mazes without even seeing the player wouldn't make sense
Answer by deltamish · Mar 22, 2013 at 07:02 AM
hi
here is a simple AI code that moves th character without using character controller or Navmesh
Edit
#pragma strict
var Attackdist:float = 5;
var Player:Transform;
var MoveAnim:AnimationClip;
var AttackAnim:AnimationClip;
var speed:float;
var damage:float = 5;
var model:Transform;
private var _me:Transform;///this the character
private var tempspeed:float;
function Start(){
tempspeed = speed;
if(!_me)
_me = transform;//cache for better performance
model.animation[MoveAnim.name].wrapMode = WrapMode.Loop;
model.animation[AttackAnim.name].wrapMode = WrapMode.Once;
}
function Update(){
//transform.LookAt(Player);
_me.rotation = Quaternion.Slerp(_me.rotation,Quaternion.LookRotation(Player.position - _me.position),Time.deltaTime * 9);
_me.eulerAngles = Vector3(0,_me.eulerAngles.y,0);
var fwd:Vector3 = _me.TransformDirection(0,0,1);
transform.position += fwd*speed*Time.deltaTime;
model.animation.Play(MoveAnim.name);
if(Vector3.Distance(_me.position,Player.position) <=Attackdist){
speed = 0;
Attack();
}else{
model.animation[AttackAnim.name].layer = -1;///add this if not it will not play move anim
speed = tempspeed; //initial speed
}
}
function Attack(){
//yield WaitForSeconds(0.5);//wait 0.5 seconds before playing anim
if(!model.animation.IsPlaying(AttackAnim.name))
model.animation[AttackAnim.name].layer = 1;//add this if not it will not play attack animation
model.animation.Play(AttackAnim.name);
Player.SendMessage("TakeDamage",damage,SendMessageOptions.DontRequireReceiver);
}
Hi deltamish.
Your script it is very good and work perfectly.
But only on one model of zombie, this script don't work.
When the game start, this zombie follow the player but the animation of zombie model rotate model.
sorry for my bad english
see my video to understand my problem.
http://youtu.be/GU6JkzNPpPg
What differences are there between navmesh and character controller?
Thank you very much for your help.
hi Thats pretty strange,, you can fix this by Removing rotation from the animation of the model (did you animate it your self)
and your english isnt that bad
Can you upload your model so that i can see the problem
PS.By the i observed you were using Unity 4 i am using unity 3.5.6 i am planning to upgrade it for a long time but i fear the upgrading may taking a long time and i read somewhere in unity Answers that some projects were ruined after upgrading to unity 4 i dont know if thats true so do you think upgrading to unity 4 is worth it and is there realtime reflection in unity 4(I think i read this somwhere)
Hi deltamish.
how to Remove rotation from the animation?
i have upload the free model (downloaded on the web, it is free) on my google drive
Link : https://docs.google.com
I'm using Unity 4 from a few months and my projects work perfectly, and i don t use realtime reflection.
Thank you very much for your help!!
hi i got the files i will try to fix it now and by the way did you create all that animation and textures
Really nice
hi found out the problem the problem was the forward of the model is actually right of the model that means the front(facial) part of the model is not forward(blue coloured arrow) in its local or world axis its is right(red color arrow) so all you have to do is create a new empty gameobject and rotate in such a way that the facial part of the model and the forward(blue arrow) of the empty gameobject face same direction then make the zombie object child of empty object
and if you want even more realistic animation(animation spedd very very important) just lerp from 0 to speed and divide
Answer by Omir · Mar 20, 2013 at 06:06 PM
If You are beginner believe me brother AI is most worst thing is game Development , no one here will help you with this stuff ... You Search for Term A* algorithm and get started but i will prefer to you to use a plugin known as "RAIN AI" Best part of plugin is its free and it support zombies comes with video tutorials by both RAIN and Tornado Twins Cheers here is the Link RAIN AI : http://rivaltheory.com/tag/rain-ai Grab your free copy now .. !!! Happy AI