I want an object to circle or orbit around another object. For example, the earth orbits the sun. I'd rather use a coding solution instead of creating a circular path.
Getting An Object To Orbit Around Another Object
Started by el_tavish, Jan 07 2008 04:13 AM
7 replies to this topic
#1
Posted 07 January 2008 - 04:13 AM
#2
Posted 07 January 2008 - 04:24 AM
Place these two pieces of code into the respective events of the orbiting object. Be sure to replace object_being_orbited with the appropriate object or instance id.
Creation Event:
Step Event
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.
Creation Event:
orbit_angle = 0; orbit_radius = 128;orbit_speed = 360 / room_speed; //change of angle per step
Step Event
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.
#3
Posted 07 January 2008 - 04:27 AM
Well, you could do it like this:
create:
myspeed=1; //smaller if the radius is bigger
dir=90; //start above point of orbit
radius=100;
orbitx=100;//point to orbit around
orbity=100;
step:
x=orbitx+lengthdir_x(radius,dir);
y=orbity+lengthdir_y(radius,dir);
dir+=myspeed;
And that should work
create:
myspeed=1; //smaller if the radius is bigger
dir=90; //start above point of orbit
radius=100;
orbitx=100;//point to orbit around
orbity=100;
step:
x=orbitx+lengthdir_x(radius,dir);
y=orbity+lengthdir_y(radius,dir);
dir+=myspeed;
And that should work
#4
Posted 07 January 2008 - 04:32 AM
or
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
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
#5
Posted 07 January 2008 - 04:42 AM
this is kinda embarrasing but up until now I've never had used the same piece of code for more than one object. NEVER! I'm not quite sure how I managed to do this but I have very little knowledge of how I'm supposed to bring the code from the script section into various objects.
So I gotta ask, do I put the second part into the scripts section and the first part into the coding of the object?
So I gotta ask, do I put the second part into the scripts section and the first part into the coding of the object?
#6
Posted 07 January 2008 - 04:46 AM
the second part is saying what the arguments are supposed to be like in the D&D actions you know where the 'execute code' action is well the next one is execute script like one of the scripts from the side bar and thats where you put the arguments in you see what i mean
P.s. its ok to be embrassed i didnt know that or even code 'GML' intil 3 months past have GM
P.s. its ok to be embrassed i didnt know that or even code 'GML' intil 3 months past have GM
#7
Posted 07 January 2008 - 05:18 AM
I've been using registered GM for just over a year
. Despite all the coding and stuff that I've learned I never learned about scripts. hahaha. gotta learn sometime I guess. Thank you
#8
Posted 07 January 2008 - 05:25 AM
thats ok as long as i helped
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











