Help - Search - Members - Calendar
Full Version: Point Direction
RPG RPG Revolution Forums > Game Engines > RPG Maker 2000 / 2003 > General Game Engines Discussion
Rukiri
This is something I wrote to originally translate into ruby(which it will eventually) but I first had to figure out what point direction does. Obviously it points to x,y,x2,y2 and trig is involved but after disecting the function I came up with something that did exactly what I needed.

I generally only use this for a-rpgs when it comes to battle collisions, so it points from herox,heroy,aix,aiy and depending on each X/Y it'll move straight back or diagonally.

This is also great for space shooters.

Script:
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;
Shadyone
I know how to script in gml but what the hell I can't understand that script o.O
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.