a strange problem ?

Hi …

I’m trying to make a FPS game , but I have a problem :

I used this code “Physics.Linecast(transform.position,Target.position,hit)”
to let the solider know if he can or can’t see the player …

the problem when I go in front of the solider he will shoot me ,and between the first and the second shoot about 0.2 seconds . now if I turn the player ( his back to solider ) and walk to the solider he will attack me in very very speed ,he’s will not stop for 0.2 as first …

were is the problem …

thanks in advance…

link of the soldier script :
http://www.mediafire.com/?b5qe0uzy3bq6nbb

this video about the problem :
http://www.mediafire.com/?83n6p44uanqb4dv

Soldier.js (Added by alucardj):

function Shoot() { 

    var hit : RaycastHit; 
    SoilderEye = Vector3(transform.position.x,0.5,transform.position.z);

    if ( (ActionOfAttacking == WaitAction.AttackWhenInCircle)&&(Physics.Linecast(SoilderEye,Target.position,hit))
      && (hit.collider.gameObject.tag=="Players")&&(Vector3.Distance(transform.position,Target.position)<SeeTargetDistance) )
    {
       ShootingWhenSee();
    }
    else if ( (ActionOfAttacking == WaitAction.AttackChangePlaces)&&(Physics.Linecast(SoilderEye,Target.position,hit)) 
      && (hit.collider.gameObject.tag=="Players")&&(Vector3.Distance(transform.position,Target.position)<SeeTargetDistance) ) 
    {
       ShootingChangePlaces(); 
    }
}

function ShootingWhenSee() {

    var forward = transform.forward;
    var targetDir = Target.position - transform.position;
    var angle = Vector3.Angle(targetDir , forward);  

    //-----< Shoot At Target >-----//
    if (angle > SeeTargetAngle)
    {
       //-----< Rotate To The Target >-----//
       var targetPoint = Target.position;
       var targetRotation = Quaternion.LookRotation (targetPoint - transform.position,Vector3.down);
       transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation,Time.deltaTime * 25);
       transform.rotation.x = 0;
       transform.rotation.z = 0; 

       AimAndShoot();
    } 

}

function AimAndShoot() {

    var hit1 : RaycastHit;  
    var direction = transform.TransformDirection(Vector3.back);

    if ( ShootingTimer > 0 )
       ShootingTimer --;
    else 
       ShootingTimer = ShootingSpeed;

    if ((ShootingTimer==ShootingSpeed)&&( Physics.Raycast(ShootPos, direction, hit1, 15) ) )
    { 
       var newSight;

       if(hit1.collider.gameObject.tag =="Players")
       {
          //print("Player got shooted");
          //var newBlood = Instantiate(Blood,hit1.point, Quaternion.identity);
          //newBlood.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit1.normal);
       }
       else
       if(hit1.collider.gameObject.tag =="Cars")
       {
          var newSpark = Instantiate(Spark,hit1.point, Quaternion.identity);
          newSpark.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit1.normal);

          newSight = Instantiate(SightOfBullet,hit1.point, Quaternion.identity);
          newSight.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit1.normal);
          newSight.parent = GameObject.Find("AllBullitSights").transform;
       }
    }

    currentanimation = "shoot"; 

    if (Muzzle1.renderer.enabled)
    {
       Muzzle1.renderer.enabled = false; 
       Muzzle2.renderer.enabled = false;
       Muzzlelight.transform.GetComponent(Light).enabled = false;
    }
    else
    {
       Muzzle1.renderer.enabled = true;
       Muzzle1.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward); 
       Muzzle2.renderer.enabled = true;
       Muzzlelight.transform.GetComponent(Light).enabled = true;   
       audio.clip = SoilderSounds.Shoot; 
       audio.Play();  
    } 

}

It’s simply that you don’t have a “ShootingTimer”. You just have a “ShootingCounter” which counts down by one each frame. Your framerate is probably higher when the other model isn’t rendered, therefore your “counter” counts faster.

Make your ShootingTimer a float variable instead of int and so this instead:

ShootingTimer -= Time.deltaTime;

This will reduce ShootingTimer by 1.0 every second. So if you want one shot every second you have to set ShootingTimer to 1.0 if you want two shots in a second set it to 0.5