Mood: Dark, Suspenseful Length: 3-4 minutes Speed: Medium Looped: Yes Description of game style: The game is set in an alternate universe called The Dark Zone. Preferred format: Can I have an OGG and an MP3 file for it please? Thanks. Instruments: It would be really cool if you could put some human voices in there. I'll leave the rest up to you. Thanks. Can you PM the link to me when you are done? Thanks.
As shown by this equation, the force which gravity has on an object is equal to the constant of gravity, multiplied by the two masses multiplied by each other and divided by their distance squared.
So, we already have the values we want to work with: you can easily assign "mass" variables to your objects based on their apparent size, you can set a constant for gravity (DON'T use GM's - set your own variable, this is just for the math), and you can know the distance squared by doing power(point_distance(x1,y1,x2,y2),2).
Essentially, you need to set up a loop in which one object adds force to itself based on doing this same equation with all of the other objects in the room. You can find all other gravity-inducing bodies by doing something like this:
grav = 0.25;
var a, b, m1, m2, dist;
for (a = 0; a < instance_number(obj_planet); a += 1)
b = instance_find(obj_planet,a);
if !(b == id or b == noone)
m1 = mass;
m2 = b.mass;
dist = power(point_distance(x,y,b.x,b.y),2);
First, I set "grav" to 0.25, representing our constant for gravity (which, again, cannot be the one set by Game Maker.) Then, I run through all of the instances of "obj_planet" in the room - you would replace this with whatever you want to apply gravity to. If the instance found is the instance doing the checking or "noone" (another GM constant), then the loop should ignore it, as otherwise we will receive errors. Then, we get the mass of the first and second objects (you should have set this already), and the distance squared. Finally, we run the formula. Please note thatthis code assumes some kind of collision detection - if dist is 0, then you will get a division by 0.
This code also assumes that the object running it is an instance of obj_planet. How does this work for you?
That works brilliant, thanks. However, how can I add a collision thing that works? I tried doing what I normally do, which is x=xprevious, and y=yprevious, but that just got them stuck on each other, with ones shooting out of the blob of asteroids occasionally.