• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Ellipse Orbit with Scaling Objects

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
 
J

Joshua Allen

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

Code:
// 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;
 
There are many ways to do this but here is something that I just wrote up to help you get started:

// 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;
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.
 
Top