- Home /
I need help creating a ZombieAI for my Walking Dead Game
I want the zombie ai that would go after the sound of a gunshot and not follow the player and I want it to go after the player when the player is in the zombies field of view. I also want the zombie to go after many people with the player tag. If the player goes into a house I want the zombie to go after the door even if the player goes out the other way. I want the zombie to DETROY the door. I also want the zombie to follow other zombies that have a target to go after. If not then they roam slowly. Here is what I have so far.
var door : Transform; var target : Transform; var myTransform : Transform; var moveSpeed = 2; var rotationSpeed = 4 var height = 0; var hasTarget = false; var rayDistance : float = 10.0; var timeToStopAttacking : float; var fieldOfView : float = 70; var timer : float = 10.0; var distanceToEnemy;
function Awake () {
myTransform = transform;
}
function Update () {
If((Input.GetButtonUp("Fire1")) && (distanceToEnemy <= rayDistance * 1.5 )) {
hasTarget = true;
}
target = GameObject.FindWithTag("Player").transform;
distanceToEnemy = Vector3(myTransform.position, target.position);
rayDirection = target.position;
//Raycast
var hit : RaycastHit;
if((Vector3.Angle(rayDirection, transform.forward) < fieldOfView){
if(Physics.Raycast(myTransform.position, myTransform.forward, hit, rayDistance)){
if(hit.transform.tag == "Player") && (hit.transform.tag != "Wall") && (hit.transform.tag != "Door")) {
hasTarget = true;
}
}
}
// GOING AFTER ITS TARGET
if(hasTarget) {
var lookDir = target.position - myTransform.position
var lookDir.y = height; // Height is the height difference
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed Time.deltaTime;
}
}
Please format all your code properly using the 10101 button. Try breaking this down into one question, not I want I want I want, makes it hard to follow what part is not working.
Your answer
Follow this Question
Related Questions
whats wrong with my enemy respawn script???? 1 Answer
When I Destroy 1 Enemy They all Get Destroyed. PLEASE HELP 2 Answers
Space between gameobjects 1 Answer
Any good FPS zombie game names? 1 Answer
Player colliding with animations 0 Answers