Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How can I ground enemies and use target transform?

$
0
0
Hello game developers, I have a question. I have an enemy character that is targeting my player character and when it follows me the enemy is floating like a ghost. my question is can somebody explain to me how to ground the enemy and also help me out with my script please? the following is my monsterAI script that is attached to the enemy. var distance; var target : Transform; var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 1; private var isItAttacking = false; var enemySound : AudioClip; 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); audio.PlayOneShot (enemySound); } @script RequireComponent (AudioSource)

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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