I'm coming from game maker and looking to convert code, the simplest seems to be point a object or enemy ai in a direction when he's attack by my hero or ally ai's.
Here's the code.
x1 = argument0;
y1 = argument1;
x2 = argument2;
y2 = argument3;
dt = sqrt(sqr(x2 - x1) + sqr(y2 - y1));
dir = 0;
if (x2 > x1){
if (y2 > y1){
dir = ceil(arcsin((y2 - y1)/dt));
}else{
dir = ceil(360 - arcsin((x2 - x1)/dt));
}
}else{
if (y2 > y1){
dir = ceil(180 - arcsin((y2 - y1)/dt));
}else{
dir = ceil(180 + arcsin((x2 - x1)/dt));
}
}
return (((arctan2(argument0-argument2,argument1-argument3)* (180/pi))) + 450) mod 360;
in gm It'd be used like so.
speed=2; direction=point_dir(herox,heroy,aix,aiy);