different Swarm behaviours inside a pool

19 views
Skip to first unread message

ventoline

unread,
Jun 14, 2013, 10:59:53 AM6/14/13
to hypefr...@googlegroups.com
Hi,
I am implementing  the swarm behaviour, i have a pool of mc, which swarms around a moving target, then more targets come in to play, though i am chercking which target is the closest to the mc and assign this target as a Point to the swarm, but it looks that all mc switch to the same target, here is the code:


if( Point.distance( new Point( clip.x,clip.y ), new Point( targets[closest].x,  targets[closest].y )) < Point.distance( new Point( clip.x,clip.y ), new Point( targets[i].x,  targets[i].y )) )
        {closest = i;}
}
trace("closest to clip is"+ closest);
var swarm:Swarm =BehaviorStore.retrieve(clip, "swarm") as Swarm;
    var closestSPoint = new Point(targets[closest].x, targets[closest].y);
    swarm.point = closestSPoint;
}


Should i create a swarm for each object in the pool? or a swarm per target? I am not sure either how to remove and assign new Swarm to the object on the pool


Thanks, :)
Reply all
Reply to author
Forward
0 new messages