Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Make my enemy stop when he reaches me.

$
0
0
This is my EnemyAI script its just for some zombies, they don't attack its for a scary walkthrough type of thing. Its just that they get on top of the palyer and then block the players view from the end credit. What can I change so that when they are a foot away they stop moving toward the player? And one other thing, that is less important now, they hover above the floor when walking over to me. And hover above/around my head. If its an easy fix post that to! Thanks in advance! var target : Transform; //the enemy's target var moveSpeed = 3; //move speed var rotationSpeed = 3; //speed of turning var attackThreshold = 1.5; // distance within which to attack var chaseThreshold = 10; // distance within which to start chasing var giveUpThreshold = 20; // distance beyond which AI gives up var attackRepeatTime = 1; // delay between attacks when within range private var chasing = true; var myTransform : Transform; //current transform data of this enemy function Awake() { myTransform = transform; //cache transform data for easy access/preformance } function Start() { target = GameObject.FindWithTag("Player").transform; //target the player } function Update (){ // check distance to target every frame:1 var distance = (target.position - myTransform.position).magnitude; if (chasing) { //rotate to look at the player myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); //Quaternion.LookRotation(target.position.x, myTransform.position.y, target.position.z) - myTransform.position); //move towards the player 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>