instantiating a projectile continually over time

I have a prefab moving left to right across the screen I can get it to shoot at the player/camera on the z axis once at the start but I would like to have the enemy object keep shooting at the player as it moves across the screen. I have tried different things but I can’t seem to get it to work. Any help would be great.

var projectile : Rigidbody;
var initialSpeed = 20.0;

function Update()
{

	{
	// create a new projectile, use the same position and rotation as the Launcher.
	var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
		
	// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
	instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, initialSpeed, 0));

	// Ignore collisions between the missile and the character controller
	Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
	
}

}

Put instantiatedProjectile.LookAt(player) after the Instantiate.

I suggest you to put this code in the FixedUpdate() instead of Update() and use transform.LookAt(player) (for the enemy tranform) before the Instantiate.

Also, put a gap between the projectiles or they will collide with themselves.

Hello,

Since your question is so broad, I’ll just give you a just as broad answer :slight_smile:
One solution would be to make a timer, every time the timer reaches or goes below 0, you shoot and reset the timer. Thats it.

Hope this helps,
Benproductions1