Quantcast
Viewing all articles
Browse latest Browse all 1488

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; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>