title: Trying to spawn enemies in a circle around the player in Unity
body: <p>2D sidescroller. I'm trying to instantiate 5 Enemy prefabs around the player following a circle, surrounding him. Ive been using the player position to create the radius but I cant figure it out.</p>
  
  <p>Any ideas?</p>
  
  <p>Here's an image of my goal:
  <img src="https://i.stack.imgur.com/V8fJo.jpg" alt="enter image description here"></p>
  
  <blockquote>
    <p>Position your prefab above your player, however far away you'd like with whatever radius.</p>
    
    <p>Calculate how much of an angle you'd need to rotate for however many enemies you'd like to instantiate. So if you want 5 enemies, you could go like:</p>
    
    <p>float angle = 360f / 5;
    Use Transform.RotateAround to rotate your prefab around your player by angle however many times, and Instantiate a copy of the prefab. This way you'll get a perfect circle.</p>
    
    <p>Alternatively, if you didn't want to use RotateAround, you could have your single prefab as a child of a gameObject, change the child's transform.localPosition to be whatever distance from its parent's center, then Rotate the prefab's parent transform by angle 5 times.</p>
  </blockquote>
  
  <p>I slowly worked my way into a workable solution with his instructions. I'm sure there's a prettier way to do it, and Id love to hear other inputs, but this works just fin. Here's what I'm doing:</p>
  
  <pre><code>private int num_enemies=5;
  float angle =  360f/5;
  void Start () {
      player = GameObject.FindGameObjectWithTag ("Player");
       //emptyenemy is a gameobject I have positioned right on top of the player
      //This is hardcoded and needs to change to position itself betwwen the player and the top of the screen
  
              Vector3 enemyPos = emptyEnemy.transform.position;
  
      while (num_enemies&gt;0) {
          Instantiate (EnemyPrefab, enemyPos, player.transform.rotation);
          EnemyPrefab.tag = "Enemy" + num_enemies;
          num_enemies--;
          emptyEnemy.transform.RotateAround (player.transform.position, Vector3.forward, angle);
          enemyPos=emptyEnemy.transform.position;
      }
  }
  </code></pre>
  
  <p>I'm going to be playing around with this, trying to make them orbit and what not. Id love to hear other peoples approaches as well. </p>