Code Snippet: Orbiting
Engine: Game Maker: Studio
https://www.yoyogames.com/studio
In your rotating object’s CREATE event, drag over an, “Execute Code” block and type:
// Setup the orbiting object’s variables
pDir = 0; // Where the orbiting object starts (0-360)
pDistance = 100; // The distance from the main object this orbits
pSpeed = 1; // Speed of the orbit
In your rotating object’s STEP event, drag over an, “Execute Code” block and type:
// Set the movement of your orbiting object
x = [yourObject].x + lengthdir_x(pDistance, pDir)
y = [yourObject].y + lengthdir_y(pDistance, pDir)
// Based on which direction you want, you can use +/- when adding the speed
pDir += pSpeed;
I hope that this helped anyone looking for some orbiting planets, buffs, or tornadoes in the future!
Cheers,
Joshua Long










0 comments