kamiyasi
Member
Hi there. Let me explain what I'm working on.
I have a star, with a gravitational radius that's 200 times it's size.
I use this code...
to tell my planets to have a smaller gravitational pull towards the star if they're further away from it. [ In this project, global.pulldistance is equal to 200 and mass is the size of the star ]
What I would like to do is find an equation that sets each planet's initial xspeed and yspeed so that once the room starts, they enter a near perfect orbit around the star regardless of their distance from it (unless they're outside of the gravitational raidus of course, in which case they wouldn't move at all)
I'm using the following equation so far which gets the planets in an orbit, but it's far from a perfect orbit.
If anyone has a good algorithm for what I'm trying to achieve, I'd appreciate it
I have a star, with a gravitational radius that's 200 times it's size.
I use this code...
Code:
var gdir = point_direction( x,y,other.x,other.y );
var gdis = point_distance( x,y,other.x,other.y );
var pstrength = ( (other.mass*0.000001) );
var pull = (pstrength) * clamp(( ((gdis / (other.mass*global.pulldistance) )*-1)+1 ) ,0,1);
///add gravitational pull
xspeed += ( lengthdir_x( pull, gdir) );
yspeed += ( lengthdir_y( pull, gdir) );
What I would like to do is find an equation that sets each planet's initial xspeed and yspeed so that once the room starts, they enter a near perfect orbit around the star regardless of their distance from it (unless they're outside of the gravitational raidus of course, in which case they wouldn't move at all)
I'm using the following equation so far which gets the planets in an orbit, but it's far from a perfect orbit.
Code:
var i;
for (i=0; i<6; i++)
{
with instance_create( x+lengthdir_x(20000+(10000*i),(45*i)),y+lengthdir_y(20000+(10000*i),(45*i)),obj_planet)
{
///set initial momentum
var gdir = point_direction( x,y,other.x,other.y );
var gdis = point_distance( x,y,other.x,other.y );
var pstrength = ( (other.mass) );
var pull = (pstrength) * clamp(( ((gdis / (other.mass*global.pulldistance) )*-1)+1 ) ,0,1);
var inertia = 0.04 + (pull*0.000009);
xspeed += ( lengthdir_x( (inertia), gdir+90) );
yspeed += ( lengthdir_y( (inertia), gdir+90) );
}
}