• 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!

moving an object in a circle

G

gibberingmouther

Guest
i'm not sure how to code moving an object in a circle around a point. i'm sure the solution is simple but i got nothin'. :|

the equation for a circle i believe is x^2 + y^2 = r^2. i tried to turn this into code somehow but couldn't think of how to do it.
 

FrostyCat

Redemption Seeker
That form is useless for circular movement, you want the parametric form.

Create:
Code:
cx = room_width/2;
cy = room_height/2;
r = 100;
theta = 0;
theta_speed = 2;
Step:
Code:
theta += theta_speed;
if (theta >= 360) theta -= 360;
x = cx + lengthdir_x(r, theta);
y = cy + lengthdir_y(r, theta);
 

TheouAegis

Member
y = sin(direction) * distance from center
x = cos(direction) * distance from center
direction += revolution speed

But I like lengthdir_* functions better. Just putting the code out there for completion.
 
Top