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

How can I randomize the speed of enemy movement?

$
0
0
How can I edit the following script so my enemies follow the player at a random "moveSpeed" between 5 and 10? var target = GameObject.Find("aggro").transform; //the enemy's target var moveSpeed = 10; //move speed var rotationSpeed = 5000; //speed of turning var myTransform = this.transform; //current transform data of this enemy function Update () { target = GameObject.FindWithTag("aggro").transform; //target the player myTransform = this.transform; //rotate to look at the player this.myTransform.rotation = Quaternion.Slerp(this.myTransform.rotation, Quaternion.LookRotation(target.position - this.myTransform.position), rotationSpeed*Time.deltaTime); //move towards the player this.myTransform.position += this.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>