Last visit was: It is currently Thu Dec 05, 2024 11:56 am


All times are UTC-05:00




Post new topic Reply to topic  [18 posts ] 
Author Message
 Post subject:Physics (Gravity)
PostPosted:Sun Sep 27, 2009 8:34 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Sun Sep 27, 2009 10:25 pm 
 

Joined:Thu Apr 28, 2005 3:57 pm
Posts:175
AOL:DKWiz214
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.

_________________
The light shall be your demise.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Sun Sep 27, 2009 11:30 pm 
Literally Nine
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:1263
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.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 7:45 am 
User avatar
 

Joined:Sat Jun 06, 2009 1:21 am
Posts:581
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:

_________________
I'll see you on the dark side of the (ferrous) moon.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 8:32 am 
 

Joined:Thu Apr 28, 2005 3:57 pm
Posts:175
AOL:DKWiz214
If we're talking about masses large enough to create noticeable gravitational fields, something tells m there is no atmosphere...

_________________
The light shall be your demise.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 9:50 am 
User avatar
 

Joined:Sat Jun 06, 2009 1:21 am
Posts:581
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:

_________________
I'll see you on the dark side of the (ferrous) moon.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 10:32 am 
Literally Nine
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:1263
Maybe you could solve a three-body problem?

*giggle*


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 1:50 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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?

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 2:28 pm 
Literally Nine
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:1263
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.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Mon Sep 28, 2009 3:03 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Tue Sep 29, 2009 1:08 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
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

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Tue Sep 29, 2009 8:22 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Tue Sep 29, 2009 9:54 pm 
User avatar
 

Joined:Sat Jun 06, 2009 1:21 am
Posts:581
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...

_________________
I'll see you on the dark side of the (ferrous) moon.


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Wed Sep 30, 2009 5:28 am 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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).

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Physics (Gravity)
PostPosted:Wed Sep 30, 2009 6:30 am 
 

Joined:Thu Apr 28, 2005 3:57 pm
Posts:175
AOL:DKWiz214
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.

_________________
The light shall be your demise.


Top
Offline  
Display posts from previous: Sort by 
Post new topic Reply to topic

All times are UTC-05:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created by Miah with assistance from hyprnova