# Gather objects in one point

Hello! Is it possible to gather rigidbodies in one point, so they move to each other and meet in point, average for all of them. Just like magnets… I am trying different ways, but still can’t get it.

Searching forums, I found a nice workable code for magnet-like effect, but it gather all objects around one (for which this code is applied). So it’s like a “magnetic bomb”. Not what I need exactly… Anyway, here is it:

``````var blastForce = 0;
var implode = true;

function FixedUpdate () {
var things : Collider[] = Physics.OverlapSphere(transform.position, blastRadius);
for (i=0; i<things.length; i++){
if (things_.attachedRigidbody && things*.attachedRigidbody != rigidbody){*_
``````

var offset : Vector3 = (transform.position - things*.transform.position);*
}
}
}_

function Update() {
var key1 = Input.GetKey(“1”);
var key2 = Input.GetKey(“2”);
if (key1 && implode){
implode = false;
blastForce = -100;
}
if (key2 && !implode){
implode = true;
blastForce = 50;
}
}

Couldn’t you just average the positions of all the points and then apply a force on all the objects towards that point?

something like this:

``````float blastForce = 5.0f;
Vector3 total = Vector3.zero;
for(thing in things)
{
total += thing.transform.position;
}
Vector3 center = total/things.length;
for(thing in things)
{