How do I set up an orbit using physics?

0 favourites
  • 5 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi everyone!

    This is my first post on the forums, but I would love some help with setting up a dynamic orbiting system with the 'physics' behaviour. I've looked at a heap of different topics on the forums relating to orbit, but alas, as yet I am yet to fix my problem. Basically, I want the user to be able to drag and drop (using the plugin) a 'planet' and have it automatically fall into a perfect circular orbit of a 'sun' (both objects).

    As my project currently stands, I am using events to specify that as soon as the planet is 'dropped' onto the layout, a force is enacted upon it pushing it towards the sun (to simulate gravity) using a relative formula that says force = distance(planet.X,planet.Y,Sun.X,Sun.Y)/100. This works fine, because the further away the object is, the weaker the 'gravity' is.

    I also have it set up so that when the planet is dropped, there is a physics impulse striking it at angle(Planet.x,planet.Y,Sun.X,Sun.Y), which means that wherever the planet is placed, it begins an anti-clockwise rotation. Again, this works as planned.

    My issue lies entirely with the force of impulse itself. At the moment I get irregular elliptical orbits depending on how far the planet is from the sun, which makes me assume that the 'force' of the impulse will need to be relative to the distance between the planet and the sun, however as to the formula for the force, I am clueless.

    Thank you so much in advance for any help anyone can give!

  • I had fun building a project like that too when I was exploring the physics side of things. Personally I prefer the irregular elliptical orbits as I find it fun to play with the differing factors. It's also more realistic as our solar system is not completely regular.

    That said, if you want to go for perfectly circular movement you could don't really need to use the physics at all, but could simply plot the movement based on the formula for a circle with the sun at the centre point. You'd then use a series of setX/setY values with wait periods in between to determine the speed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For the correct formulas you can use this for calculating the forces:

    http://en.wikipedia.org/wiki/Newton%27s ... ravitation

    And this for the initial velocity:

    http://en.wikipedia.org/wiki/Orbital_sp ... ital_speed

    I made a capx without physics here:

    how-do-i-implement-orbits-w-o-span-class-posthilit-physics-span-beh_p771265?#p771265

    And here is info how to do it with physics:

    orbital-velocity_p730036?#p730036

  • So sorry it took me so long to reply! I wanted to implement all your help and get it working before getting back to you! Thank you SO MUCH for all your help guys!

    hundredfold, I agree, my first project was exactly that, a setup where you could alter variables and then see how it effected the orbit, but for this one I needed 'perfect' orbit.

    R0J0hound, I can't tell you how much you helped me what I needed to do! Thank you so much man! Incidentally, I noticed in the thread you linked, you said that you had to find a conversion factor of 48.8, I THINK (and only think, because I'm new to the physics plugin) that that may be needed because impulse 'force' (or rather how fast it travels once the impulse has been applied) follows the algorithm that 'Velocity = Impulse/Mass (2500)', which would mean that different levels of 'force' for an impulse can lead to some crazy velocity (in pixels per second).

    Anyway, I have everything working as it should now, thanks again!

  • The 48.8 factor is due to some unit conversions.

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