- Home /
Enemy (AI) Doesn't shoot weapon projectile, until after the player is gone.
Okay I am trying to understand a few things here. First things first, why does my AI only shoot the projectile after the player is gone? I looked at the script and I found something that may be contributing to it, HOWEVER, I deleted it, saved it, and tried it, however the problem still persists. It has to do with this section listed in BOLD below.
First Script
var Turret : GameObject;
var Bullet : Transform;
var BulletSpeed = 5000;
var Character : Transform;
var SavedTime = 0;
if(Vector3.Distance(Character.position, transform.position)>20)
{
var Shoot : AnimationEvent = new AnimationEvent();
Shoot.time = 2.166;
Shoot.functionName = "SHOOT";
Turret.animation.clip.AddEvent(Shoot);
}
function SHOOT ()
{
var bullet = Instantiate(Bullet, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
}
second script
var Turret : GameObject;
var Bullet : Transform;
var BulletSpeed = 5000;
var Character : Transform;
var SavedTime = 0;
if(Vector3.Distance(Character.position, transform.position)>0)
{
var Shoot : AnimationEvent = new AnimationEvent();
Shoot.time = 2.166;
Shoot.functionName = "SHOOT";
Turret.animation.clip.AddEvent(Shoot);
}
function SHOOT ()
{
var bullet = Instantiate(Bullet, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
}
Third Script
var Turret : GameObject;
var Bullet : Transform;
var BulletSpeed = 5000;
var Character : Transform;
var SavedTime = 0;
var Shoot : AnimationEvent = new AnimationEvent();
Shoot.time = 2.166;
Shoot.functionName = "SHOOT";
Turret.animation.clip.AddEvent(Shoot);
}
function SHOOT ()
{
var bullet = Instantiate(Bullet, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
}
Can anyone help me understand what the problem is?
Your answer
![](https://koobas.hobune.stream/wayback/20220613102820im_/https://answers.unity.com/themes/thub/images/avi.jpg)