Ferrous Moon
http://www.ferrousmoon.com:80/forums/

Physics (Gravity)
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1916
Page 1 of 2

Author:  eddieringle [Sun Sep 27, 2009 8:34 pm ]
Post subject:  Physics (Gravity)

Going along with my previous post, I need gravity in a game I am working on. (Still don't know how to use VBOs, heh). Anyway, each ball will have it's own mass property, so I need a gravitational pull effect. There is no floor, so they won't fall down, just really swing between each other and orbit around the larger masses. And yeah, it's 2d.

Author:  Soldier of Light [Sun Sep 27, 2009 10:25 pm ]
Post subject:  Re: Physics (Gravity)

F = GmM/d^2
F = ma

So basically, the acceleration of the object orbiting a large mass should be:
a = GM/d^2
Where G is a giant constant, M is the mass of the big mass, and d is the distance between the two (center to center). I don't remember G off the top of my head, it might be 9e9 but idr if that's something else.

So once you have an object's acceleration, every second you add that to its velocity, and every second you add its velocity to its position. Though in your case you would want to do it every frame and scale down your accel/vel/pos values accordingly.

Author:  Miah [Sun Sep 27, 2009 11:30 pm ]
Post subject:  Re: Physics (Gravity)

I can ruin your day with such things as air resistance, but in the end it'll be more correct and you'll have an honest to god terminal velocity.

Yeah... tell me if you want it. If you ask, you have to use it though.

Author:  sentinel [Mon Sep 28, 2009 7:45 am ]
Post subject:  Re: Physics (Gravity)

Quote:
I can ruin your day with such things as air resistance, but in the end it'll be more correct and you'll have an honest to god terminal velocity.

Yeah... tell me if you want it. If you ask, you have to use it though.
So just be a real bOitch and include things like air humidity to influence air resistance :classy:

Author:  Soldier of Light [Mon Sep 28, 2009 8:32 am ]
Post subject:  Re: Physics (Gravity)

If we're talking about masses large enough to create noticeable gravitational fields, something tells m there is no atmosphere...

Author:  sentinel [Mon Sep 28, 2009 9:50 am ]
Post subject:  Re: Physics (Gravity)

Quote:
If we're talking about masses large enough to create noticeable gravitational fields, something tells m there is no atmosphere...
OR IS THERE? :sleazy:

Author:  Miah [Mon Sep 28, 2009 10:32 am ]
Post subject:  Re: Physics (Gravity)

Maybe you could solve a three-body problem?

*giggle*

Author:  eddieringle [Mon Sep 28, 2009 1:50 pm ]
Post subject:  Re: Physics (Gravity)

No, there is no atmosphere. And I want a programmatic way to implement gravity, I know the formula already (thanks though). ;)
Like, how would I use it to determine it's X and Y position, and how would I determine those if they also orbit around the object?

Author:  Miah [Mon Sep 28, 2009 2:28 pm ]
Post subject:  Re: Physics (Gravity)

Show me in a drawing that you actually know how to do this.

If you have no clue, then I can draw my own for you, but it's not going to do you a lot of good.

Author:  eddieringle [Mon Sep 28, 2009 3:03 pm ]
Post subject:  Re: Physics (Gravity)

Quote:
Show me in a drawing that you actually know how to do this.

If you have no clue, then I can draw my own for you, but it's not going to do you a lot of good.
Of course I have no clue, it's why I'm asking for help.

Author:  FinalWarrior [Tue Sep 29, 2009 1:08 pm ]
Post subject:  Re: Physics (Gravity)

Quote:
Where G is a giant constant, M is the mass of the big mass, and d is the distance between the two (center to center). I don't remember G off the top of my head, it might be 9e9 but idr if that's something else.
A nitpick:

G is the universal gravitational constant and it is by no means "giant". It's approximately 6.67428 x 10^-11. (The, uh, unit of measurement is confusing difficult to state with words.)

Well, I guess you could call it inversely giant. 0.0000000000667428 is a pretty small value - in the hundred billionths.

-- Griffinhart

Author:  eddieringle [Tue Sep 29, 2009 8:22 pm ]
Post subject:  Re: Physics (Gravity)

So, I calculate the force of gravity between the player and the surrounding masses, but how do I decide when that force is strong enough (when it's higher than any other force, right?) and how would that mass get closer to the player? (The force is the rate of acceleration towards the player?)
Seems to me like a lot of calculations must take place.

Author:  sentinel [Tue Sep 29, 2009 9:54 pm ]
Post subject:  Re: Physics (Gravity)

Quote:
So, I calculate the force of gravity between the player and the surrounding masses, but how do I decide when that force is strong enough (when it's higher than any other force, right?) and how would that mass get closer to the player? (The force is the rate of acceleration towards the player?)
Seems to me like a lot of calculations must take place.
Well, supposedly, if you use the right constants and masses, combined with the correct functions, the calculations will be done for you...

Author:  eddieringle [Wed Sep 30, 2009 5:28 am ]
Post subject:  Re: Physics (Gravity)

Yes, I am already able to have it calculate Distance between the two and the force between the two, they are printed in the Window caption (I don't want to deal with OpenGL fonts yet, heh).

Author:  Soldier of Light [Wed Sep 30, 2009 6:30 am ]
Post subject:  Re: Physics (Gravity)

So once you have the force, you divide it by the player's mass to get acceleration. Then every frame you would add acceleration/fps to the x and y velocity of the player, depending on the direction of the force.

So, if your player is directly to the right of the mass, you would add only to the -x. If your player is at an angle, you would break the force into x and y components using sin and cos.

Once you've calculated the new velocity, you would then add that velocity/fps to the position of your player. Again, use x and y, don't recombine them. This should give you the motion that you're looking for.

Page 1 of 2 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/