PDA

View Full Version : gravitation formulas ???



zylum
March 27th, 2003, 08:14 PM
does anyone know a formula that causes an object to gravitate towards another stationary object? In the formula you can include the distance from the object and the objects mass as well as anything else you can think of.

I tried to figure it out myself, but the effect is not realistic. In my version, the gravity becomes stronger when the two objects are far apart and it becomes weaker as the objects are closer together... here's what I used...

_root[nm].dx += ((_root[nm].diffx*-0.9999)+(_root[nm].diffx))*_root[nm].mass/3;

the same for dy but using diffy...

the diffx and diffy are the distance apart and the mass is the sized of the stationary object... I hope someone can help me with this...

- mike

senocular
March 27th, 2003, 08:32 PM
I have something around here somewhere...
Ah, there it is!

I made in Flash 5 a while back - probably a lot cleaner if I redid it in MX ;)

You're welcome to it though

http://userpages.umbc.edu/~tmccau1/flash/test/gravity.swf
http://userpages.umbc.edu/~tmccau1/flash/test/gravity.fla

zylum
March 27th, 2003, 08:38 PM
thanks, i'm taking a look at them now...

zylum
March 27th, 2003, 08:47 PM
is there any other way to do this? any simpler way using 2 formulas one for the x direction and one for the y? i only need the gravity for one object... any help?

morse
March 27th, 2003, 08:50 PM
http://download.com.com/3000-2400-10122652.html?tag=lst-0-1
This is way fun to watch.

it has nothing to do with AS, just gravity

senocular
March 27th, 2003, 09:41 PM
Originally posted by zylum
is there any other way to do this?
Theres always another way :)


Originally posted by zylum
any simpler way...
More than likely


Originally posted by zylum
any simpler way using 2 formulas one for the x direction and one for the y?
dividing one function into 2? Why seperate? Is that supposed to make it easier? 8]

pom
March 29th, 2003, 01:22 PM
I didn't have a look at Sen's *very nice* file, but why don't you implement Newton's law of gravitation. The formula is pretty straightforward and all you'll have to do is tweak the numbers a bit.

pom :)

zylum
March 29th, 2003, 01:42 PM
I'm not sure what the formula should look like... i tried this but the result is really wierd:q: the formula I used is:

_root[nm].dx += 9.8*(_root[nm].mass/_root[nm].diffx);
_root[nm].dy += 9.8*(_root[nm].mass/_root[nm].diffy);


i dunno what's wrong... maybe someone can help me with the formula

-mike

Marz
March 29th, 2003, 05:34 PM
Well.. Let's look at the actual physics formulafor gravitational pull between two masses.

Force = (Gravitational Constant * mass1 * mass2)/ (r * r);

r is the distance between the two objects..

So... Let's do a pretty rough estimation on how close they are instead of doing it as a tight wad..

r = Math.abs(object1._x - object2._x);
r = Math.abs(object1._y - object2._y);

The Gravitation Constant.. of G.. You will have to play around with this figure... But it will always stay the same.

The mass's... You could make a mass forumla saying

mass1 = object1._width * object1._height;
mass2 = object2._width * object2._height;

So.. Now that we have all our constants... We can place them into one gigantic formula.

ForceX = (9.8 * (object1._width * object1._height) * (object2._width * object2._height) / Math.abs((object1._x - object2._x) * (object1._x - object2._x));
ForceY = (9.8 * (object1._width * object1._height) * (object2._width * object2._height) / Math.abs((object1._y - object2._y) * (object1._y - object2._y));

Of course you can just give your objects a mass ahead of time and that's it... But I personally Like to use the method I did above.

Of course.. In a computer programming environment you need to do this however...

ForceX +=
ForceY +=

And then... Take the object you wish to move and add on that force...

_root.object1._x = ForceX;
_root.object1._y = ForceY;

If this startsgiving you funn results.. Try getting rid of the Math.abs.. :)

playamarz :player: