- Home /
Enemy follows player then attacks!
Hi everyone. I am creating a zombie maze game. Pretty obvious what I've got to do. Got my character working tagged as "player", I've got box colliders on the bushes and i have an exit! I now am trying to add zombies to the game. I have no start script I am afraid. The zombies need to have 3 working animations "Zidle" and "Zwalk" then "Zattack". I need the zombies to see me and follow within a certain distance, whilst not walking through the walls. Then when they are close to the player, attack me! I will worry about health and that lot later!!! any help appreciated thank you!!!
Answer by Berenger · May 13, 2012 at 06:19 PM
First step, you need a destination. To detect the player, you can use Raycasts, trigger and overlapsphere. To pick a random pos for idle, you have Random.inUnitSphere.
The steering. Your zombi need to be able to go from point A to point B with the correct rotation. The simplest way is to use transform.Translate, or lerp and position.
If there is an obstacle, you can either make the zombi bump into it (they are stupid, after all) or find a path. If you have pro there you can use unity's path finding (but I can help) or you can try Aron's one or Angry Ant's one.
Answer by spike2192 · May 13, 2012 at 07:52 PM
But i have no skills in javascript so i wouldn't even know where to begin with it all :/ thank you for your help, i will do some more searching
If you are that new at coding, try something easier first. If you really want to stick with that project, here is a $$anonymous$$imal code :
var player : Transform; var speed : float = 5.0;
function Update() { transform.position = Vector3.Lerp( transform.position, player.position, Time.deltaTime * speed );
var dist = (transform.position - player.position).sqr$$anonymous$$agnitude;
if( dist < 1.0 ) // attack
}
Your answer
Follow this Question
Related Questions
NPC code, works great, besides them being in the ground. 2 Answers
Enemies running when they should be following. 1 Answer
HitSpark for Enemy Collision 1 Answer
How to rig an enemy? 1 Answer