Jump to content
  • Advertisement
Sign in to follow this  
pseudobot

[Orbital] Gravity

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all! :) I am wondering how to calculate gravity for a planet & have objects act accordingly. Basically, this is what I want to do: Have a few planets, for now lets just leave it at one. This planet has a mass of 20 (goes from 0-100). Then I have a asteroid. This asteroid should now be attracted by the planets gravity. However, this should be calculated in to a XVelocity and a YVelocity. ANd that part I am unsure of. Hope someone can help me out here, and if my post is not detailed/confusing than I will draw some pics to clarify. Thanks in advance! :)

Share this post


Link to post
Share on other sites
Advertisement
BEFORE edit

To calculate into a xvelocity and yvelocity, you would need to find the gravitational force that planet exerts, then find out the acceleration, and then apply the acceleration to the asteroid. The asteroid's velocity would then change.

AFTER edit

To calculate into a xvelocity and yvelocity, you would need to find the gravitational force that planet exerts, then find out the x and y components of the acceleration, then apply the acceleration components to the current velocity components.

Share this post


Link to post
Share on other sites
Hi there Pseudobot,

Playing around with gravity simulation is really fun, and I've done so for a couple of years :-) To help you along, here's a very small, well commented code sample demonstrating how to simulate gravitationally interacting objects on a computer. It's written in a language called freebasic which you might not know, but it's easily readable, and once you understand the principles behind it, you should be able to port it to whatever language you use.

http://www.jernmager.dk/stuff/freebasic/gravity_02.zip

good luck with it!

Cheers,
Mike

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!