Orbital velocity

0 favourites
  • 6 posts
  • 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

  • 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.

  • 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.

  • 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: 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.

    app.box.com/s/a93qqsubba14i0nuelwm

  • 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.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you both - for the maths, information and capx. I'm off to play...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)