T
TurtleBitAlex
Guest
Hello. Im currently trying to build a gravitational model of planets in Gamemaker2. So far gravity and everything is working great except one problem, Every like second or few the objects just randomly stop and basically the physics has to reset so all momentum and stuff is gone. Any Help? Code
Here is a current example. Executable https://drive.google.com/file/d/1o02ghdhWwqCH960ar5toSyL4a6XKDLjV/view?usp=sharing
Code:
n = instance_number(obj_object)
G = 6
for (var i = 0; i < instance_number(obj_object); i++) {
bodies[|i] = instance_find(obj_object, i);
}
for( var i = 0; i < (n-1); i += 1 ) {
_a = bodies[|i];
for ( var j = i + 1; j < n; j += 1 ) {
_b = bodies[|j];
if _b != _a {
_x = _a.x - _b.x;
_y = _a.y - _b.y;
_f = G / power(_x*_x+_y*_y,1.5);
_f1 = _a.mass * _f;
_f2 = _b.mass * _f;
if point_distance(_a.x,_a.y,_b.x,_b.y) > 64
{
_b.phy_speed_x += _x * _f1;
_b.phy_speed_y += _y * _f1;
_a.phy_speed_x -= _x * _f2;
_a.phy_speed_y -= _y * _f2;
}
}
_b.phy_speed_x = _b.phy_speed_x
}
}