Hi everyone, I’m trying to have bullets auto target.
So far I have it working on all targets but when target gets destroyed and when new target selected bullet no longer are auto targeting. Can someone please help here is the Js script:
var target : GameObject;
var targetAlive : boolean = false;
function Update ()
{
if(Enemy_Collisions.e_alive)
{
if(targetAlive == true)
{
var new_target : Vector3 = target.transform.position - transform.position;
rigidbody.velocity = new_target.normalized * 100;
transform.LookAt(target.transform.position);
}
}
if(!Enemy_Collisions.e_alive)
{
targetAlive = false;
}
}