Login | Register

Circle around another

August 2, 2006, 11:38 by Calle
[loading]
-->
To make one object go around another in a circular path, of course, we need two objects: the object to circle and the object to be the centre. I call these ObjCenter and ObjCircel. These are the values that I assign in the create event of object circle:

dist = distance_to_object(ObjCenter);
dir = point_direction(x,y,ObjCenter.x,ObjCenter.y);


This is to calculate where to start. This will make the object keep the initial distance. In step event we need to calculate the movement as well:

dir +=3;
x = ObjCenter.x+lengthdir_x(dist,dir);
y = ObjCenter.y+lengthdir_y(dist,dir);


dir+=3 defines how many degrees the object should pass in each step. This decides how fast he will circle. The lengthdir functions calculate the x position and the y position by the length and direction that we define.

The first piece of code should be placed in create event and the second in step event. I provide an example that you may look at:
http://gmtutorials.com/files/circlex.gm6

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games