I am trying to understand the logic behind Game Maker's
point_direction(x1, y1, x2, y2) function, which takes the vector from
(x1, y1) to
(x2, y2) and returns the counter-clockwise angle it forms from the positive x-axis, in degrees.
How do I implement this functionality in my own code?
Here's my attempt so far:
//custom_point_direction script var x1 = argument0; var y1 = argument1; var x2 = argument2; var y2 = argument3; var targetAngle; targetAngle = radtodeg(arctan2(y2,x1)); return -targetAngle;
Here's an example of how I want to use this function. This is the step event of an object that should face/point towards the player object:
direction = custom_point_direction(x,y,player_obj.x,player_obj.y); image_angle = direction;
This does not work like GameMaker's
point_direction() function. How do I make my
custom_point_direction() work similar to