[for the impatient]
//-And heres the context-free application of this concept, simplified.
//-Its a nice little skeleton for scripting directional logic into
// more complicated player/npc 'reactions' to elements with an (x,y) origin.
//////////////
//ACTUAL SCRIPT BELOW#!
function faceOffDirToObject() {
angletoobj = REPLACE_WITH_ANGLE_FUNCTION; //try not to get a NaN here
dir = int(.637 * angletoobj + .5) + 3 % 4;
//*now do something with that dir
}
So I figured I’d throw my share into commune pile to help along with playerworld development.
I’ve been converting my weaponset to a click interface for my 5 year old nephew who cant yet grasp the W,A,S,D,<,^,>,v two hand harmony.
Thanks goes to the Reborn Team for keepin it alive and in the spirit of oleskool graal, and yes for saving me, friends and family $$ / month.
//FaceOffDirection by Strider
//////////////////
//-originally I just wanted the player to face the mouse simply like:
// anglefromplayer = f (mousex,mousey)
//*calculate angle from player to the
// mouse (probably with the trusty
// getangle(dx,dy) command)
// playerdir = g (anglefromplayer)
//*yield the correct direction from that angle.
// I'm defining 'correct direction' as:
// NAME DIR RANGE(degrees)
// up 0 [45,135)
// left 1 [135,225)
// down 2 [225,315)
// right 3 [0,45) U [315,360) <=non-continuous issue
// So heres what I had:
if (created) {timeout =.05}
if (timeout) {
dx = mousex-(playerx+1.5);
dy = mousey-(playery+1.5);
angle = getangle(dx,dy);
pi = 3.14;
anglewithoffset = angle + (pi / 4);
//*we have to offset the angle, so
// that our RANGE for DIR = 3 becomes continuous
serial = int( anglewithoffset / (pi / 2) );
//*this way, if we divide the
// offset angle by (pi/2), then round down,
// we will get an number from a consecutive series
playerdir = serial + 3 % 4;
//*and finally we use mod to translate/tweak
//the series into the range we need ([0,1,2,3])
}
//-Admittedly, the example application above will yield a NaN when:
// dx = dy = 0, from the (trusty) getangle(dx,dy) command.
//-Its really up to the individual how he/she wants to deal with this.
// eg. you could just leave it and take whatever you get from the function
//-And heres the context-free application of this concept, simplified.
//-Its a nice little skeleton for scripting directional logic into
// more complicated player/npc 'reactions' to elements with an (x,y) origin.
//////////////
//ACTUAL SCRIPT BELOW#!
function faceOffDirToObject() {
angletoobj = REPLACE_WITH_ANGLE_FUNCTION; //try not to get a NaN here
dir = int(.637 * angletoobj + .5) + 3 % 4;
//*now do something with that dir
}
Alot of possible applications for this script based on a combination of how you define the angle function, what you do with the dir when you get it (setting a .gani would be the start), or even some hacking of dir function itself if you’re savy.
And with all the great things being done with triggeraction on Gserver +/- NPC-Server, a lot of interesting things you can do if you’re creative…and can config params.
eg. making all players or npc(with dir) near you to turn to notice you, then run off into the other direction, because you’re too badaz for this and that reason
-Cheers