How can I make a lot of homing rockets to follow my player, and when my player dies of one of the rockets, the other rockets just keeps going forward on the same direction as they were going before?
This code only looks at the player, and follows it, which is how it’s supposed to work, but when the player dies, they’re just stuck on the same position of where they were when the player died.
I want them to just keep moving forward on the same angle as before endlessly (I have a destroyer collider).
var dir = playerPosition - transform.position;
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
if(player.alive)
{
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.position = Vector3.MoveTowards (transform.position, playerPosition, Time.deltaTime * speed);
}
Thanks!