- Home /
 
Multiple enemy prefabs moving towards a single goal. Need help!
Here is my code to move my enemies:
     void FixedUpdate(){
         Vector3 targ = goal.transform.position;
         // Get a direction vector from us to the target
 
         dir = targ - bombSpawner.transform.position;
     
         // Normalize it so that it's a unit direction vector
         dir.Normalize();
 
         //move towards dir (goal)
             transform.rigidbody2D.AddForce (dir * 2f);
 
 
         }
 
               They all spawn and move towards the bottom left for some reason. My goal.transform is at 0,0,0 though! :(
Any ideas or help? I'm new to C# and unity in general so if I didn't provide enough info, please let me know.
Thanks.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Pyrian · Apr 11, 2014 at 11:26 PM
In line 5, remove "bombSpawner." so each enemy will move from its current position towards the goal, rather than from the spawner's position towards the goal.
Your answer