How to move an object around an orbit using Physics Force?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Idea: Asteroid turns around a central object in orbit using Force Physics

    I want the ability to make asteroids bounce off each other on collision or be pushed by other objects so they return to their orbits.

    My failed attempt with AI help... C3P https://www.dropbox.com/scl/fi/adllfgp1xp3vw72kxvg6s/Physics-Orbit-03.c3p?rlkey=4bc0mb1qnvrga0dnbr1nvt3tk&st=iggnyeyo&dl=0

    Illustration of what I want to achieve:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Normally a physics orbit is done by applying a gravity force (roughly k/distance^2 toward the center object) and setting the tangent velocity just right so it stays in that orbit instead of falling down or flying off into oblivion.

    And while doing a setup like that is possible, it would be fragile in that the asteroid belt would fall apart once the player hit it once.

    Moving back into orbit after being bumped off isn’t realistic behavior so may as well do something unrealistic like applying a force to the asteroids to a location further along the orbit.

    For each asteroid 
    — set ang to angle(planet.x, planet.y, astroid.x, astroid.y)+10
    — astroid: apply force 0.1 toward position (planet.x+200*cos(ang), planet.y+200*sin(ang)

    10 is how many degrees ahead in the orbit to target. You can fiddle with that.

    0.1 is the strength of the force. Adjust if too fast or slow.

    200 is the radius of the belt from the planet. Can be anything you like.

    You may or may not want to limit the speed of the astroid. Either by high linear damping or applying a force in the opposite direction of the velocity if the speed is too high. If the speed is uncapped I can imagine colliding with an astroid could send it flying off into oblivion.

  • Wow! R0J0hound Sorry for late replay. Thank you very much for detailed explanation. Your formulas work exactly like I imagined and even better.

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