| Move towards instance nearest |
//////////////// MOVE TOWARDS NEAREST //////////////////// // // Copyright Simon Donkers 3-7-2006 // www.simondonkers.com - gmmentor@simondonkers.com // // argument0 is object name // argument1 is max change or cource per turn. (optional) // Use 360 to make it move in a straight line // when using multiple objects select one parent object. // Note: set the speed yourself! // ///////////////////////////////////////////////////// var nearest,change,wanted; if instance_exists(argument0) then { if (argument[1]=0) argument[1]=10; nearest=instance_nearest(x,y,argument0) wanted := point_direction(x,y,nearest.x,nearest.y); change=min(abs(direction-wanted),argument1); if direction-wanted>180 then direction += change; else if wanted-direction>180 then direction += -change; else if direction-wanted<180 and direction-wanted>0 then direction += -change; else direction += change; if direction>360 then direction += -360; if direction<0 then direction += 360; } |
Tip: Have a look at the tutorial How to execute a script
User comments
| Injection posted at 2006-01-16 19:51:29 | ![]() |
| ZeRo posted at 2006-11-28 13:20:35 | ![]() |
| Simon Donkers posted at 2006-11-28 18:58:16 | ![]() |
| mohammed-f posted at 2007-01-14 13:19:44 | ![]() |
| Simon Donkers posted at 2007-01-14 17:15:10 | ![]() |
| scorpafied posted at 2007-05-17 04:21:03 | ![]() |
| werewolf posted at 2007-05-23 10:10:15 | ![]() |
| werewolf posted at 2007-05-23 10:28:12 | ![]() |
| werewolf posted at 2007-05-23 20:25:19 | ![]() |
| scorpafied posted at 2007-06-05 02:19:14 | ![]() |
| Works Great ^_^ posted at 2007-06-12 04:15:57 | ![]() |
| scorpafied posted at 2007-06-21 04:02:06 | ![]() |
| jonat posted at 2007-07-09 15:00:38 | ![]() |
| joe posted at 2007-10-08 21:53:57 | ![]() |
| joe posted at 2007-10-08 21:55:48 | ![]() |
| someone posted at 2008-02-13 10:23:45 | ![]() |
| anonomys posted at 2008-05-31 04:43:40 | ![]() |
| anonomys posted at 2008-06-05 08:57:52 | ![]() |
| eastley posted at 2008-07-27 04:48:34 | ![]() |
| heromedel posted at 2008-08-03 03:06:47 | ![]() |




