How do I make gravitational orbits?

1 favourites
  • 6 posts
  • Hello everyone, I would like a help to know how to do realistic physics in Construct, I will give an example. I have a large circle and a small one, when the small circle approaches the big one it is pulled by gravity causing an orbit. At the same time pressing the screen applies a force to control the fall without it touching the big circle.Therefore, applying force to it is ejected out of the gravitational field and launched to another nearby circle with gravity as well. upload.wikimedia.org/wikipedia/commons/0/0d/Orbital_resonance_of_Mercury.gif

  • How are you looking to handle objects that approach straight on at speed? In reality these objects would never be pulled into orbit. Are you looking to force all objects to enter an orbit if they are slowed down enough?

  • Exactly that, imagine that when you approach the circle it will be pulled to the center but when you touch the screen it will push outwards, but if you keep pressed, it will continue to rotate around the circle

  • The force of gravity between objects can be done with:

    F=G*m1*m2/r^2

    Where

    m1 and m2 are the masses of the two objects and r is the distance between them.

    G is a constant. It comes from

    en.m.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation

    But since we are not dealing with real world scales we can just fudge it.

    You can try the following. Also to get the moon to orbit you just have to have the perpendicular velocity high enough.

    Global number a=0

    Global number r=0

    Global number f=0

    For each planet

    — set a to angle(moon.x, moon.y, planet.x, planet.y)

    — set r to distance(moon.x, moon.y, planet.x, planet.y)

    — set f to 100 * moon.physics.mass * planet.physics.mass/r^2

    — moon: physics: apply force (f*cos(a), f*sin(a))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ROJO I was intrigued by the OP's question and I've been working on a similar principle to what you described. I think using a built in movement behaviour to handle the movement when the object is not in orbit is probably the way to go. For when the object is being influenced by the planet I've built a custom orbit behaviour where both the force of the object and the opposing force of the player input determines the velocity of the object, which subsequently determines the speed at which the object enters/exits an orbit. It's not ready to add here yet but if you have any other input I would be interested to see other peoples takes on the problem.

  • > The force of gravity between objects can be done with:

    F=G*m1*m2/r^2

    Where

    m1 and m2 are the masses of the two objects and r is the distance between them.

    G is a constant. It comes from

    https://en.m.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation

    But since we are not dealing with real world scales we can just fudge it.

    You can try the following. Also to get the moon to orbit you just have to have the perpendicular velocity high enough.

    Global number a=0

    Global number r=0

    Global number f=0

    For each planet

    — set a to angle(moon.x, moon.y, planet.x, planet.y)

    — set r to distance(moon.x, moon.y, planet.x, planet.y)

    — set f to 100 * moon.physics.mass * planet.physics.mass/r^2

    — moon: physics: apply force (f*cos(a), f*sin(a))

    Great explanation, I had already tried to use Newton's theory but I couldn't apply it correctly, but his explanation helped me to understand the concept and to get what I needed, thanks to everyone :D

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