AI-trigger-shot-problem

hey guys, i´m trying let a turret shoot at the player, when he/she/it^^ enters specific range (the radius of the collider…)…when the player is out of range(collider), the shootings should stop
so i added a sphere collider to my turret and enabled the trigger.

the trigger works so far…enabled…disabled - ok.
the turret is targeting the player - ok
…the turret doesn´t start to shoot…it just starts, when i´m 10 meters away from it, but the collider is set to a radius of 100 meters. :?:

var LookAtTarget:Transform;
var damp =5;
var LaserPrefab: Transform;
var savedTime = 0;
var speed = 6;
var aggrocheck = false;

function OnTriggerEnter  (other : Collider) {
	if(other.gameObject.tag == "Player")
		aggrocheck = true;
}

function OnTriggerExit  (other : Collider) {
	if(other.gameObject.tag == "Player")
		aggrocheck = false;
}
function OnTriggerStay  (other : Collider) {
	if(other.gameObject.tag == "Player")
		aggrocheck = true;
}

function Update () 
{	
		if(LookAtTarget  aggrocheck)
			{
			
				var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
				transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
				var interval:int = Time.time;
				var oddeven = (interval/2);
				
				if(oddeven)
				{
					Shoot(interval);
				}
			}

}

function Shoot(interval)
{	
		if(interval != savedTime)
		{
		print ("shot");
		var laser = Instantiate(LaserPrefab, transform.Find("turretSpawnPoint").transform.position,transform.rotation);
		
		laser.rigidbody.AddForce(transform.forward * speed);
		savedTime=interval;
		}

}

Well i’m a C# coder but it looks OK to me. I’d say that your triggers look to be fine so look at what’s happening in your update, put a print / debug statement inside Updates

if(LookAtTarget  aggrocheck) 
{

Check to see if this is happening at 100 meters or at 10 meters, assuming it is happening at 100 meters then put one inside your

function Shoot(interval) 
{

Just basically see what areas of your code are being stepped into when it’s not firing correctly, hopefully that’ll point you in the right direction.

the turret colliders are working correctly (inrange —> they aim at me), when i leave the range (print out of range - they don´t aim at me)…when i start shooting the turret, the lasers disappear when hitting the turret colliders…and the turrets lasers disappear too…

when i disable the trigger in the inspector the player is stopped by the magic invisible collider wall;) but the lasers not…strange…

the only tags the script uses to check is the Player tag…

ok, forget it:) i´ve found a better solution:)

function Update () 
{

    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("Player");
    //assumes only one player
    var thePlayer:GameObject = gos[0];
    var dist = Vector3.Distance(thePlayer.transform.position,transform.position);
   
    if(dist<=seeDistance){
        isChasing= true;
    } else {
        isChasing=false;
    }
}
function Update () 
{		
		/*if(aggrocheck)
		{*/
		if (EnemyAI.isChasing)
		{
			if(LookAtTarget )
				{
					print ("in range");
					var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
					transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
					var interval:int = Time.time;
					var oddeven = (interval/2);
					
					if(oddeven)
					{
						Shoot(interval);
					}
					
			}	
		}
		else
						print ("out of range");
		
}

just set the seedistance to any range, works fine to me, without any trigger stuff