How do I implement orbits w/o physics behavior?

0 favourites
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • I've realized the physics behavior is really slowing my game down so I'd like to not use it. I really only need it to get one sprite to orbit one or more other sprites. Is there a way to do this?

  • Yes there is.

    just pin the object to rotate to an invisible sprite with the Rotate behaviour.

    Attached is the capx. hope it helps.

  • Thanks dude. This method may work.

    I want to have a character that can instantly switch from orbiting a planet to freely floating. I want the character's angle and velocity to factor into how it orbits a planet instead of simply orbiting at a predetermined speed and distance.

    EDIT: Maybe this won't work. If the character is floating towards a planet, I don't want it to start spinning around that planet when I active orbit. I'd like the character to go 'through' the planet and back and forth.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I to am trying to make a object orbit and the pin and rotate method while easy is a little jerky and I would like smooth motions. I am using some Trigonometry but I seem to be having some issues with my math.

    Each tick move at angle Tan((distance(Star.X, Moon.Y, Star.X, Star.Y))/(distance(Moon.X, Star.Y, Star.X, Star.Y)))

    its 3:30AM and it looks right but idk as Moon.X approaches 0 Moon.Y approaches 1. Giving if the planet was one unit away.

    I tried putting in just tan(60) but my planet keeps moving at 0*. Could tan() be bugged?

  • Old school Trig: Make invisible object and have it rotate every tick. Make actions for the orbiting object........set x to invisible object.x+(cos(invisible_object.angle)*100) and set y to invisible object.y + (sin(invisible_object.angle)*100) . You could replace the 100 with whatever distance you want or use variable's that change . This also works with spiraling orbits with a few additions to code . Tan is not relevant in this situation .

  • CrazyVulcan If you get that going, would you post a capx?

    granpa What additions would you make for a spiraling orbit?

  • Here is an example of an orbit based on Newton's law of universal gravitation.

    https://dl.dropboxusercontent.com/u/542 ... orbit.capx

    Basically it means that the velocity of the moon is taken into consideration.

  • R0J0hound Thanks! Do you happen to know if this could work with two or more planets (with alterations)?

    EDIT: Also, I would like to turn to incorporate the bullet behavior into the moons so they bounce off solids. How would I do this?

  • For more planets change the "every tick" to "for each planet" and add another "every tick" event below and move the "set position" action to that.

    To make it work with the bullet behavior you'll have to covert the speed and angle of motion to vx and vy in an "every tick" before the events and back at the end of the events. Also the "set position" can be removed and the overlap and bounce event should be either before or after the events.

    Here are the conversion formulas:

    Vx=speed*cos(angle of motion)

    Vy=speed*sin(angle of motion)

    And

    Speed=distance(0,0,vx,vy)

    Angle of motion=angle(0,0,vx,vy)

  • bachrock I did not get my idea to work but I did come up with a number of ways to get it to work, including the Pin&Rotate method. Granpa's steps work great and I also found for cool elliptical orbits have a rotating object that your planet is pined to and have it move every tick so far. I did not like this last one as it was not very precises but it did look cool. I also made a invisible circle sprite with two refpoints and had the sun and planet on each end and just had the circle rotate, which was time consuming.

    The Pin&Rotate is the best the resin I had trouble with it was because my sprites were too small. so it was jumping form pixel to pixel. I just scaled it up a bit and it works beautifully.

  • awesome stuff

    ive been looking all over the forums for a couple days for solutions on how to do radial gravity(?). however all the examples i found have the bodies (planets/moons) only acting towards a central object (blackhole/sun) and ive tried to expand on the formulas but im not learned like R0J0 so i fail hard at creating a complete model where all the bodies interact with each other.

    what im trying to do:

    solar system with a star in the middle exerting radial gravity to the very edges of the solarsystem (layout). the star should probably not use box2d physics for mass as it would have to be impossibly huge, but instead get mass from an instance variable.

    orbiting bodies(planets) that do use physics and each have radial gravity depending on physics mass (calculated by radius right?)

    so for example in my fantasy version of this example it would be possible to place a large body in orbit around the star and a smaller body in orbit around the large body (ie both bodies are affected by the star gravity but the bodies also interact with each other and the large body has enough gravity to keep the smaller body in orbit, like a moon)

    ill keep trying but any help would be appreciated!

  • openfocus

    Here's a way to do it with the same formula I used before.

    https://www.dropbox.com/s/eldpa0s7zvfr3 ... .capx?dl=1

    /examples22/orbit2.capx

    A family was used so I can pick two different instances of the same object type. Also all the numbers are kind of arbitrary, e.g. G, masses, velocities and positions. I just tweaked them until I got an acceptable motion. However there is no reason why you couldn't use scaled values from actual planet data.

  • openfocus

    Here's a way to do it with the same formula I used before.

    https://dl.dropboxusercontent.com/u/542 ... rbit2.capx

    A family was used so I can pick two different instances of the same object type. Also all the numbers are kind of arbitrary, e.g. G, masses, velocities and positions. I just tweaked them until I got an acceptable motion. However there is no reason why you couldn't use scaled values from actual planet data.

    that is amazing! thanks rojo!

  • Here is an example of an orbit based on Newton's law of universal gravitation.

    https://dl.dropboxusercontent.com/u/542 ... orbit.capx

    Basically it means that the velocity of the moon is taken into consideration.

    Sorry for the thread necro. You wouldn't still happen to have this, would you?

  • link updated

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