Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Want to make a following enemy freeze when visible by main camera

$
0
0
Hi, I'm creating a game, and I have an enemy that at the moment follows my character (main camera) but I want it to stop moving (freeze) when it is visible by the main camera, I also want it to start playing a sound when the enemy is close to my character. I know similar questions have been answered on this forum, but none in a very straight forward way, because I am new to this, so my knowledge is very thin. This is my entire code for the enemy at this point: var rotationSpeed = 3; //speed of turning var myTransform : Transform; //current transform data of this enemy var target : Transform; //the enemy's target var moveSpeed = 5; function Awake() { myTransform = transform; //cache transform data for easy access/preformance } function Start() { target = GameObject.FindWithTag("Player").transform; //target the player } function Update () { //rotate to look at the player myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); //move towards the player myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; }

Viewing all articles
Browse latest Browse all 536

Trending Articles



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