PreStep function to simulate gravity:

Canon.js example is helpful to an extent, however also very confusing:

Image

From this code I managed to replicate my own version:

Image

This was very confusing to figure out because the examples position was at 0,0,0 within the physics world. So my attempt worked fine until I tried to move or scale the planets and moons. It was also very important having set the correct mass radius and position for the moons physics object.

Once I realised this I was able to figure out a fix, by finding the distance between the moons and planets in the moonsPlanet_to_planetsMoon variable above. Then applying this distance to the moons force (I have also previously set the moons velocity on creation, which indicates the speed at which to travel). I also had to set the force value to 60 instead of figuring out the power of values on the fly.

 

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