Instantiate enemies around player

Hey everyone! First post, pretty new to Unity… I’ve had plenty of experience coding in Flash (AS3) and i know it’s pretty similar to Javascript so i’m doin my best to my move skills from one to the other…

But i’m attempting to make a game, and my player is standing in a particular spot and can spin 360* to look in any direction… Basically i want to spawn enemies around him at a distance of 50m away from the player… and i need the enemies to be facing the player (as they walk forward towards him)

I saw some code to make the enemies spawn within a circle, but that doesn’t keep them at a fixed distance.

So the player is in the middle, enemies spawn at a radius of 50 from the player (in any direction around the 360* and when Instantiated, they need to be facing the player…

How would i go about doing this?

Thanks guys! (and girls)

You could make a circle of empty objects around the player in 50m and name it, “Spawn1, Spawn2, Spawn3” and so on. Attach the empty objects to the graphic of the player. Make sure that the empty objects are not in the ground but in the air to fit the height of the enemy. The enemy might fall through the ground if it spawns in the ground. Next, make a script that instantiates the enemy in the spawn points that you just created (spawn1, spawn2, spawn3, …). For the facing the player and moving towards the player use this code:

var target : GameObject; //target
var speed : int; //speed

function Update()
{
        transform.LookAt (target.transform); //look at target
        transform.Translate (0, 0, speed * Time.deltaTime); //move toward target
        //the enemy will not stop when it is touching the player so you might want to modify that. I am only writing the simple script.
}

And you are done :smiley: Hope this helps.