Quantcast
Channel: Questions in topic: "quaternion.slerp"
Viewing all articles
Browse latest Browse all 133

Help with tower defense game using LookRotation

$
0
0
void LookAtEnemy() { GameObject[] enemies; enemies = GameObject.FindGameObjectsWithTag("Enemy"); float speed = 0.05f; foreach (GameObject enemy in enemies) { Vector3 enemyPos = enemy.transform.position; enemyPos.y = transform.position.y; Vector3 relativePos = enemyPos - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); float distance = Vector3.Distance(enemyPos, transform.position); if (distance < range) { transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed); } } } Here is the script which makes a turret to look at enemies. It's kind of working, but not accurate. A turret looks at enemies AND spaces between enemies. I don't want it, and I have no idea what to do. If you want more detailed information, please comment.

Viewing all articles
Browse latest Browse all 133

Trending Articles



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