Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
Version: GM 5+6 Views: 12052 Script, Game Maker 5 and 6 compatible
Filesize: 825 byte Creative Commons License

Circulair movement script

1/52/53/54/55/5 (16 votes)

A script to let an object make a perfect circulair path around a given coordinate with a given speed and radius.


 Circulair movement script
//////////////// Circulair movement script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// A script to make an object move in a perfect circle
// argument0 is x coordinate of center
// argument1 is y coordinate of center
// argument2 is radius of circle
// argument3 is angular speed. Positive is
// clockwise, negative counterclockwise
// This is the corner to turn a step. For instance
// 5 means it will turn around in 360/5 = 72 steps
// This script requires GM 5.1 or higher
//
/////////////////////////////////////////////////////
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;

Tip: Have a look at the tutorial How to execute a script

User comments

 Yibbon posted at 2005-02-13 09:53:29Quote
I use this script frequenly-flawless and handy-great job Simon!
 Bob posted at 2005-07-12 10:48:26Quote
That is awesome! Thanks a bunch for it. It works perfectly!
 Rick posted at 2006-05-03 18:21:25Quote
I bow to you and you GML uber leetness
 gmfreaky posted at 2006-07-06 17:25:21Quote
It don't works for me! wat i need to enter in the arguments?

SD: have a look at this article that explains how to execute a script. The script rather clearly lists the needed argument.
 Somebody posted at 2007-04-02 01:49:43Quote
Couldn't you also just put
"speed = 5
direction = round(random(360))"
in the object's Create event, and
"direction += 1"
in the object's Step event?

I'm not entirely sure, but it seems like it works.
 Simon Donkers posted at 2007-04-19 00:03:35Quote
@Somebody, the special thing is that you can here specify the center of the rotation. Your code would only work if the object is exactly the correct distance from the point you want to rotate about and the start direction is right and the point of rotation doesn't move.
If you want more control over how your movement should go, then you'd need my script.
 Jannes posted at 2007-05-13 20:22:03Quote
Is er ook een script waarmee je eerst ernaar toe gezogen word en er dan pas omheen gaat draaien?
 Afromonkey0 posted at 2007-05-22 21:28:35Quote
Is there a version of this which uses absolute speed instead of angular speed? because I want something to move straght, then in a circle around a point, then straight again, at the same speed. Can this be done with a script like this, or is there a different one I could use?
Thanks.
 new001 posted at 2010-06-28 11:40:23Quote
yay brilliant
 MBeentjes posted at 2011-01-20 20:24:16Quote
Thanks,

I am using it for a minigame that I am making! :)

You know from NGMC :)

Reply

Name:
Site: