How to cluster Falling objects

I have objects falling in my scene. and I want to cluster them together, They spread out as they fall. and I want to keep them together so they are easier to hit… How would I go about that?

Fortunately this is extremely easy: it takes two lines of code.

(1) pick one of the objects. we’ll call it NCO.

(2) each physics frame, for each of the objects,

(3) add a force to that object, directed towards NCO.

Simply tune the force in (3) until it looks good to you.

In other words in pseudocode: say you have the objects in an array stuff

var TuneMe:float = 5.55
NCO = STUFF[0]
foreach ITEM in STUFF
    ITEM addforce (quaterion from ITEM to NCO) * TuneMe

Alternately of course, just make a trivial one-line script “add force in direction of NCO” and you can attach that script to any and all objects you want to keep in the group.

It doesn’t matter which object you choose as the NCO. (Simply choose the first element in the array.)

Another interesting thing to do is change the NCO each frame (this would only be relevant if the items are falling for a very long time) - try it for different effects. But almost certainly, just choosing one NCO and leaving it at that will lead to a result you want, when you tune the parameter. Enjoy!

That worked! thank you very much!