• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Gravity Simulation Help, Unexpected Side Effects!



Hi, I'm in the process of trying to make a simple code that will make all objects with in a certain parent group work using simulated gravity on each other.

The idea is I could tag any object with "gravity" by making it part of that group, and I could quickly make entire, say, operating solar systems with out having to program each and every planet to interact with each and every planet.

This is my code

with (obj_Parent_Gravity)
    //g_Force = 6.673 * power(10,-11) * self.phy_mass * other.phy_mass / power(distance_to_object(other), 2);
    g_Force = 6.673 * power(2.71828,-11) * self.phy_mass * other.phy_mass / power(distance_to_object(other), 2);
    physics_apply_force(other.x, other.y, g_Force, g_Force);
The commented out variable is what I use any time I want to experiment with the force applied, the not commented out one uses the force of attraction measured between two 1kg lead weights 1 meter apart.

It follows the basic calculation for computing gravitational force in real life, which I expected to make objects pull each other towards each other all at once, allowing for a player craft or whatever to realistically zip along from one orbital path to another.


It causes rotation!

There's always at least a tiny bit, and the objects DO seem to attract towards each other. I've put a few "baby planets" in and my test shuttle always gets dragged to them.. but it does so while spinning.

Obviously, there's nothing in there telling it to spin. I am not sure if it's the natural result of attractive forces, or if I've messed up in my code, or if there is something else I haven't thought of. I'm sure it's some super simple thing I haven't thought of yet but it's been driving me up a wall for two days now and I decided to finally seek some help.

Thank you for any help you can offer.