Planet gravity:

In order to simulate gravity, in each planets preStep function you need to find the difference between the current planets position and the other planets position:

Image

Then process that distance to a suitable amount by normalising it and multiplying it by the planet mass and applying it to the planets force(velocity):

Image

Even with the gravity sim example to study this all took some time to figure out so that it works correctly. It took a lot of tweeking and console.logs but I got there in the end and am happy with this solution.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s