Orbital velocity

Get help using Construct 2

Post » Fri Jan 17, 2014 6:30 am

Making something orbit an object using physics is not hard. I have used and found many ways to do it. So Why is calculating the necessary orbit speed at a specific distance hard?

I want to create and obj1 sprite, apply physics and center it on screen. Then create an obj2 (with physics) at a random distance from obj1 and send it into orbit at a precise speed to keep it in a circular orbit.

There has to be a way to do this I have a capx using the gravity plug-in to use as an example, but you may want to do it a different way. (like using xvector variables and mass, ect)

I know the math behind this, but it just does not seem to work. Anyone want to take a crack at it with me?

https://app.box.com/s/a88x1g5z0k9qk99srvcx
B
193
S
6
G
7
Posts: 213
Reputation: 10,203

Post » Fri Jan 17, 2014 6:58 am

Unless you need Physics for another part of your game why not just use an offset "pivot point" at your sun ?

Could you also post a picture of the event sheet showing the maths (I can't open the capx because I don't have the plugin required) for me to have a play with.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Sat Jan 18, 2014 1:50 am

Hi Zetar,
I finally got around to looking for a solution to this. The formula for the initial velocity from wikipedia is:
v=sqrt(G*M/r)
where G is the gravitational constant, M is the mass of the object being orbited and r is the distance. Since we aren't dealing with real distances we can just use 1 instead of G.

In my tests I didn't use the gravitation plugin, instead I just applied a gravitational force to the planet every tick:
G*m1*m2/r^2 or
sun.Physics.Mass*Self.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y)^2
applied toward sun.x,sun.y

The biggest issue was that box2d units are odd so I had to find a conversion factor, which ended up being about 48.8.
So my final formula for the planet's impulse was:
Self.Physics.Mass*sqrt(sun.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y))/48.8

Plugging that into your capx worked, but the orbits aren't perfectly round when using the gravitation plugin.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Sat Jan 18, 2014 6:39 am

R0J0hound, you are a great tribute to all those who frequent this site. Thank you for taking the time to solve this. That extra 48.8 is the key. Thanks for figuring that out! I have created a simple capx with comments to help anyone else in the future who may try to do this.

Again, this is not the same as orbiting a sprite using Keslers orbit (see circle plot formula at: http://www.scirra.com/forum/make-the-player-orbit-around-a-center-point_topic61405.html. This formula will make a perfect circle around the object, which will not deviate.

This IS using the physics engine to orbit a moon/satellite around a central object with mass. The formula uses the internal Physics.mass of the objects, which is calculated by collision box size*Density variable in the physics properties. So the bigger the item, the more mass it has, multiplied by as many times you want by changing the Density property of sprite.physics.density. These objects can be made to interact with other physics objects creating somewhat realistic planetary models.

Not only the formula for gravity, but specifically the important impulse push to get the object into orbit.

https://app.box.com/s/a93qqsubba14i0nuelwmZetar2014-01-18 06:43:33
B
193
S
6
G
7
Posts: 213
Reputation: 10,203

Post » Sat Jan 18, 2014 6:59 am

I forgot to change the collision mask in the physics of each item to CIRCLE - not bounding box... That helps the orbit calculation a bit - so try it with that setting to see how it changes the movement... (The mass calculation will changes a bit, causing the calculations to change.)
B
193
S
6
G
7
Posts: 213
Reputation: 10,203

Post » Sat Jan 18, 2014 7:21 am

Thank you both - for the maths, information and capx. I'm off to play...
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882


Return to How do I....?

Who is online

Users browsing this forum: dop2000, ultrafop and 44 guests