Here's a handy script that I've used in Magikoopa Security Force for quite a few objects with homing capabilities.
Name: moveToAngle(startDirection,goalDirection)
Program: GameMaker 8.0 (Should be fine in later versions, too)
User: Magnemania
Registered: No
- //argument0: current direction
- //argument1: direction to face
- compareDirection = argument1;
- compareDirection -= argument0;
- if (compareDirection < 0)
- compareDirection = 360+compareDirection;
- if (compareDirection > 180)
- plusMinus = -1;
- else
- plusMinus = 1;
- return plusMinus;
This code compares the first direction with the second direction and provides an increment of 1 to get the first direction closer to the second; a usage of this code to make something home in on a position, for example:
Code:
direction += moveToAngle(direction,point_direction(x,y,Target.x,Target.y))
Here's a handy script that I've used in Magikoopa Security Force for quite a few objects with homing capabilities.
[b]Name:[/b] moveToAngle(startDirection,goalDirection)
[b]Program:[/b] GameMaker 8.0 (Should be fine in later versions, too)
[b]User:[/b] Magnemania
[b]Registered:[/b] No
[syntax=GML]//argument0: current direction
//argument1: direction to face
compareDirection = argument1;
compareDirection -= argument0;
if (compareDirection < 0)
compareDirection = 360+compareDirection;
if (compareDirection > 180)
plusMinus = -1;
else
plusMinus = 1;
return plusMinus;[/syntax]
This code compares the first direction with the second direction and provides an increment of 1 to get the first direction closer to the second; a usage of this code to make something home in on a position, for example: [code]direction += moveToAngle(direction,point_direction(x,y,Target.x,Target.y))[/code]