I didn't notice that before, but there doesn't seem to be a way I can fix it. Since the pull of an object is multiplied by it's mass, lighter objects will be pulled in faster than heavier objects and end up pushing the pulling object.
Yeah a few quirks I found about your example compared to mine:
-Objects move towards each other correctly, where mine is nowhere near the "right way".
-In your example, when a lighter mass object hits the heavier mass object, it seems to act as an outboard motor on a boat, and push the heavier object along. With mine, the lighter objects will bump the heavier object and cause it to shift slightly but then it will stabilize.
-Also in your example, objects of the same mass will attract PERFECTLY to each other, and behave exactly like deadeye was requesting... however if left in a massive bundle they start to spin around faster and faster until they "fling" themselves off and it becomes a big mess.
You are DEFINITELY on the right track... we just need to suss out where it is going wrong. I think a combination of your ideas and my ideas may get it working correctly.
There needs to be a correlation between distance (using the distance formula), mass (which is calculated in your example), and friction (which I think your example doesn't seem to be using?).
Having not really thought about this too well---
Perhaps a solution for force applied towards an object could be something along the lines of;
+For each instance
: sqrt((ObjectA.X-ObjectB.X)^2+(ObjectA.Y-ObjectB.Y)^2)-(ObjectA.Mass-ObjectB.Mass)
Therefore, objects with a higher mass than another, will not move towards the smaller object, rather it will attract the smaller massed objects. This will also mean that if a smaller object is too far away from another larger one, it will not be influenced by the mass as it would if the larger object were of higher mass.
I don't think I made a lot of sense there lol... I dunno... I know what I'm trying to say, perhaps I should try to make something with it instead of confusing everyone! <3
~Sol