Point direction (Game Maker convert)
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
rukiri

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);

Posted on 2011-02-22 16:06:53

mcgrue

Are you looking for help converting this to vergec or to lua?

Posted on 2011-02-22 17:09:51

rukiri

vergec.

Posted on 2011-02-22 17:16:06

mcgrue

I need a little more context. Do you have a verge demo that you're trying to add this to, or is this a general question before you start?

Posted on 2011-02-24 23:57:52


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.