C# - 2D - How can I make my homing rockets follow my player, and when my player dies, the rocket just keeps going forward?

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!

Procedure:

  1. Just add an else loop to player.alive check.

  2. In that else loop set the transform.position to the forward position so that the rocket keeps moving in forward direction.

Code:

else {
    transform.position += transform.forward * Time.deltaTime;
}