Player detection within enemy range problem

I’m currently working on a topdown shooter with a tank and my tank works just fine. But now im working on the enemy and i have occurred some problems.
Im trying to make that the enemy looks at the player when the player is in range (im using a cilynder trigger for this).
Actually the enemy looks at the player once the player enters the trigger but the enemy looks only once at him. ( it looks at the players position and keeps looking at that spot)

I know that i need to use the Update function for this but i dont know where to place it.

Please help me…

// this code is attached to the trigger (cilynder)
// the tank
var player : Transform;
// the targetter is a cilynder is use for the enemy so he looks at the player.
var targetter : Transform;


function OnTriggerEnter (other : Collider)
{
  if(other.gameObject.tag == "Player")
  {
	targetter.transform.LookAt(player);
  }
}

Use OnTriggerStay instead; the enemy will face you while your character stays inside of its range:

thanks…

im gonna try that :smile:

Works Perfectly !

thank you :smile:

depending on what you are intending for this, you could remove the additional object (collider) and use a raycast as well.

Whatever works easiest for you :slight_smile: