Getting An Object To Orbit Around Another Object
Posted 07 January 2008 - 04:13 AM
Posted 07 January 2008 - 04:24 AM
orbit_angle = 0; orbit_radius = 128;orbit_speed = 360 / room_speed; //change of angle per step
orbit_angle += orbit_speed; x = object_being_orbited.x + orbit_radius * cos(orbit_angle * pi / 180); y = object_being_orbited.y - orbit_radius * sin(orbit_angle * pi / 180);
This will cause an object to orbit around another object at a radius of 128 once every second. Change the orbit speed to change frequency. Change radius to change distance being orbited.
Edited by xshortguy, 07 January 2008 - 04:29 AM.
Posted 07 January 2008 - 04:27 AM
myspeed=1; //smaller if the radius is bigger
dir=90; //start above point of orbit
orbitx=100;//point to orbit around
And that should work
Posted 07 January 2008 - 04:32 AM
dir_now := point_direction(argument0,argument1,x,y); dir_new := (dir_now + argument3 + 360)mod(360); x := lengthdir_x(argument2,dir_new) + argument0; y := lengthdir_y(argument2,dir_new) + argument1;
argument0 = x //the x of where to orbit argument1 = y //the y of where to orbit argument2 = radius argument3 = speed
this way you only need 1 piece of code and not only that but you can put it in the side bar bit undewr script which im sure you know how to do that and then you only need one script for a whole lotta objects
make sure you change the arguments
Posted 07 January 2008 - 04:42 AM
So I gotta ask, do I put the second part into the scripts section and the first part into the coding of the object?
Posted 07 January 2008 - 04:46 AM
P.s. its ok to be embrassed i didnt know that or even code 'GML' intil 3 months past have GM
Posted 07 January 2008 - 05:18 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users