1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Rocket orbiting issues

Discussion in 'Programming' started by Lolasaurus, Aug 13, 2019.

  1. Lolasaurus

    Lolasaurus Member

    Joined:
    Sep 6, 2016
    Posts:
    8
    Hey Guys,

    I'm using some trig functions to simulate a rocket orbit around earth. Changing the direction of the rocket and applying thrust then changes the orbit shape and size etc.

    I am using the SOHCAHTOA principles to achieve this, however in places, often as vspeed crosses over 0, the rocket suddenly shoots off away from the planet. I'm guessing this is because gamemaker has an inverted y axis and so the vertical speed must be switched, however doing so doesn't give me a better result.

    Is there something more I'm missing? If i need to post some code i can do so, I just had little time to write this up.

    Thanks in advance everyone,
    Lolasaurus
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,167
    Seems you are on the right track, but hard to tell without more info.

    Add debug info displaying relevant numbers on-screen. ( x, y, vspeed, hspeed, direction, speed etc... ).

    Observe and check for anomalies to pinpoint what's going wrong.

    Post the relevant parts of your code here, along with a breakdown of what "...the rocket suddenly shoots off away from the planet" entails - (Is there any consistent pattern to it, does it always happen in the same place, does the rocket always shoot off at the same speed and direction etc...) . Diagrams and/or a video if its difficult to explain.
     
  3. Lolasaurus

    Lolasaurus Member

    Joined:
    Sep 6, 2016
    Posts:
    8
    Okay I definitely had something wrong in that attempt, the orbiting is fixed now and works well, except... The orbit constantly changes, I guess due to rounding of lengthy decimal places etc.

    Code:
    G=10
    r=point_distance(x,y,earth.x,earth.y);
    dir=point_direction(x,y,earth.x,earth.y);
    
    F=G/r^2
    
    Fv=0.2*-(F*dsin(dir));
    Fh=0.2*F*dcos(dir);
    
    vspeed+=Fv;
    hspeed+=Fh;
    
    image_angle=direction;
    Here's my simple code, Newtons Gravtitational equation has been simplified there.

    How can I increase the accuracy of the orbit so it maintains the same shape until thrust is applied etc?
     
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,871
    That's the nature of gravity. When an object's velocity is small enough, a gravity well will capture it onto an orbit. That orbit will be elliptical and its apogee and perigee will likely move around. A high-velocity object captured after a close pass will form a highly elliptical orbit, while a slow one captured at distance will form a more rounded one. To alter the orbit, thrust must be applied to change the velocity vector. To create an orbit that is approximately circular you either execute a well-planned orbital entry, or the game presents some sort of "orbital docking" feature that throws out gravity and applies cartoon physics to form a circular orbit.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice