Kind of struggled to word the question right, lets see if i can do it better here.
When I instantiate some enemies they’re spread out all over the spawner and then head towards the node they’re assigned too. However they eventually group up in single file which beats the objective of spreading them in the first place, I just want to know if I can apply the same random spread on the enemies when they reach the node, so they’re grouping rather than lining up.
Here’s how I’m currently random range spawning and how the AI move.
AI Spawning randomly around base.
var node1 : Transform;
var minionPrefab : GameObject;
var timeDelay = 5;
var range: float = 12;
function Start () {
spawnMinion();
}
function Update () {
}
function spawnMinion () {
for (var x = 1; x < 8; x++) {
yield WaitForSeconds(0.2);
var pos = transform.position;
pos.x += Random.Range(-range, range);
pos.z += Random.Range(-range, range);
var instance : GameObject = Instantiate(minionPrefab, pos, transform.rotation);
if(x == 5 ) {
yield WaitForSeconds(timeDelay);
x -= 5;
}
}
}
My AI Node is as follows (I’m working on the theory that i could apply the same random.range spread as I did with the spawning
var forwardSpeed : float = 1;
public var waypoint : Transform[];
private var pointA : Vector3;
private var currentWaypoint : int;
private var wayDir : int = 1;
function Update (){
var target: Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if ( moveDirection.magnitude < 1 )
{
currentWaypoint += wayDir;
if ( currentWaypoint >= waypoint.length )
{
currentWaypoint = waypoint.length - 1;
wayDir = -1;
}
else if ( currentWaypoint < 0 )
{
currentWaypoint = 0;
wayDir = 1;
}
}else{
velocity = moveDirection.normalized * forwardSpeed;
}
rigidbody.velocity = velocity;
}