- Home /
Can I spread the destination of AI going towards a node.
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;
}
Answer by ATMEthan · May 03, 2013 at 02:48 PM
You have to apply some sort of spread to the position of the node, like what you did with your spawner. Right now you are telling all of your minions to move to that node's position. It doesn't matter where they start if you send them all the same position they will all end up on top of each other. But if you add a random offset per minion they will scatter around the node instead of being right on top of it.
Note: You have to make sure all of the offsets are different per $$anonymous$$ion. If you don't you'll have the same problem you have now but the $$anonymous$$ions will end up at the node's offset position rather than the nodes position
Still can't figure it out, I'm playing around with a few of the things and they just keep lining up -_-
try adding a random spread to the target variable in your AI Node script