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:


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):


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.

Leave a Reply

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

You are commenting using your 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