GML Ellipse Orbit with Scaling Objects

Discussion in 'Programming' started by 2d_warrior, May 10, 2017.

  1. 2d_warrior

    2d_warrior Member

    Jul 14, 2016
    How would I program objects orbiting around an ellipse and scaling in a realistic way like this diagram below shows. At the top the scale should be 1 unless ellipse top is placed at the bottom. Not sure what the bottom of the ellipse would scaled to, but it need to interpolate between the top and bottom somehow. Half way between maximum scale and minimum scale would probably be more than half way down. Assume the orbit is a always circle in 3d, but an ellipse in 2d unless height and width are equal. The depth of each object would be based on the scale.

    Orbit Ellispe Scaling Diagram.jpg
  2. Joshua Allen

    Joshua Allen Member

    Jun 20, 2016
    There are many ways to do this but here is something that I just wrote up to help you get started:

    // size of the orbit
    var width = 300;
    var height = 50;
    // scale where 0 is the top and 1 is the bottom
    var scale = (lengthdir_y(height, direction)+height) / (height*2);
    // where is the object orbiting
    var orbit_center_x = room_width/2;
    var orbit_center_y = room_height/2;
    // move the object
    x = orbit_center_x + lengthdir_x(width, direction);
    y = orbit_center_y + lengthdir_y(height, direction);
    // how big is the object
    var size_top    = 20;
    var size_bottom =  5;
    var size = lerp(size_top, size_bottom, scale);
    draw_circle(x, y, size, 0);
    // orbit
    direction -= 2;
    // or depth = -y; I don't know which...
    depth = y;
    Xer0botXer0 likes this.
  3. 2d_warrior

    2d_warrior Member

    Jul 14, 2016
    The object does actually have a sprite, not a drawn circle in the game. I don't know if that make much difference to the code yet.
  4. joqlepecheur

    joqlepecheur Member

    Apr 4, 2017

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