Quantcast
Channel: Latest Questions by Crispinator
Viewing all articles
Browse latest Browse all 30

How do I get an NPC to stop Following a player based on distance?

$
0
0
I have a wolf. The wolf follows the player because of the tag. For some reason, when I add the section of code about distance, the wolf doesn't move. var target : Transform; var moveSpeed = 3; var rotationSpeed = 3; var myTransform : Transform; function Awake() { myTransform = transform; } function Update () { var dist = Vector3.Distance(gameObject.Position, gameObject.FindWithTag("Player").Position); if(dist < 10){ Debug.Log("Hit"); target = GameObject.FindWithTag("Player").transform; myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; } }

Viewing all articles
Browse latest Browse all 30

Trending Articles



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