Quantcast
Channel: Latest Questions by Fox-Handler
Viewing all articles
Browse latest Browse all 90

Mathf.Infinity

$
0
0
Can someone explain how Mathf.infinity is working in this script? The script is supposed to turn an instantiated bullet towards the closest target, but I can't really tell what Math.infinity is actually doing. // Update is called once per frame void Update () { float nearestDistance = Mathf.Infinity; GameObject nearestEnemy = null; foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Enemy")) { //float distance = Vector3.Distance(transform.position - obj.transform.position); float distance = (transform.position - obj.transform.position).sqrMagnitude; if(distance < nearestDistance) { nearestDistance = distance; nearestEnemy = obj; // set 1 gameObject } } if(nearestEnemy != null) { transform.rotation = Quaternion.LookRotation(nearestEnemy.transform.position - transform.position); } }

Viewing all articles
Browse latest Browse all 90

Trending Articles



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