Quantcast
Channel: Latest Questions by AxillarHD
Viewing all articles
Browse latest Browse all 10

How can I get this script to work?

$
0
0
var distance; var target : Transform; var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 6.0; private var isItAttacking = false; function Update () { distance = Vector3.Distance(target.position, transform.position); if(distance < lookAtDistance) { isItAttacking = false; renderer.material.color = Color.yellow; lookAt (); } if(distance > lookAtDistance) { renderer.material.color = Color.green; } if(distance < attackRange) { attack (); } if(isItAttacking) { renderer.material.color = Color.red; } } function lookAt () { var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } function attack () { isItAttacking = true; renderer.material.color = Color.red; transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime); } Hi everyone! So I have awesome script made by OrangeLightning - In the original post it says to "drag the target you want the AI to follow inside the slot in the Inspector named "target"." How would I do this if I want the player to be the target? I'm a beginner to scripting so i have no idea :)

Viewing all articles
Browse latest Browse all 10

Trending Articles



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