- Admin
- #1
Meh, last I took Trigonometry was in High School, and that was a very, very long time ago. I *know* thereâs a quicker way to do this, thatâd be less CPU intensive, so I thought Iâd put it out there and see if anyone could recall what that might be.
Basically, I just need calculate the directional angle between vectors, in degrees (-180/+180). These are 3d vectors, but I only need the 2d angle returned.
This is how Iâm currently doing it:
I r a little worried that maybe rough on the server CPU, and again, Iâm sure thereâs a simpler way to do that, I just canât think of how, off hand. (Although I know I donât need the conversion float to be that accurate, itâs the tangent calc thatâs the big FPU eater.)
If it was something to be called rarely, I wouldnât worry about this, but this is for making game functions â such as Maldoraâs barrier, more dependable, and could easily wound up being called every frame. Currently, Maldoraâs barrier works by having it âfaceâ the incoming target and apply its angle to the target with a whole lot of momentum â sending it flying away. This isnât dependable under certain circumstances, however. Sometimes it doesnât face towards the target proper, or in time, and sends it flying in the wrong direction, hence the application of the above command below:
In short, calc the angle based on their respective vectors, and send him flying away in that direction.
This has other applications too, as very often it is imperative to move players/monsters out of a certain area to prevent stuckage.
So, if you understood any of that, feel free to reply with any alternative solutions you may have.
Basically, I just need calculate the directional angle between vectors, in degrees (-180/+180). These are 3d vectors, but I only need the 2d angle returned.
This is how Iâm currently doing it:
Code:
//Thothie MAR 2008a - $angles(<start_origin>,<end_origin>) â returns the 2d angle between two vectors
else if( ParserName == "$angles" )
{
if( Params.size() >= 2 )
{
Vector Start = StringToVec( Params[0] );
Vector End = StringToVec( Params[1] );
float dy = End.y - Start.y;
float dx = End.x - Start.x;
float rang = atan2(dy,dx); //gets radians
float xang = rang * 57.295779; //back to degrees
RETURN_FLOAT(xang)
}
else return "0";
}
I r a little worried that maybe rough on the server CPU, and again, Iâm sure thereâs a simpler way to do that, I just canât think of how, off hand. (Although I know I donât need the conversion float to be that accurate, itâs the tangent calc thatâs the big FPU eater.)
If it was something to be called rarely, I wouldnât worry about this, but this is for making game functions â such as Maldoraâs barrier, more dependable, and could easily wound up being called every frame. Currently, Maldoraâs barrier works by having it âfaceâ the incoming target and apply its angle to the target with a whole lot of momentum â sending it flying away. This isnât dependable under certain circumstances, however. Sometimes it doesnât face towards the target proper, or in time, and sends it flying in the wrong direction, hence the application of the above command below:
Code:
local TARGET_ORG $get(PARAM1,origin)
local TARG_ANG $angles(game.monster.origin,TARGET_ORG)
setvelocity PARAM1 $relvel($vec(0,TARG_ANG,0),$vec(0,1000,0))
In short, calc the angle based on their respective vectors, and send him flying away in that direction.
This has other applications too, as very often it is imperative to move players/monsters out of a certain area to prevent stuckage.
So, if you understood any of that, feel free to reply with any alternative solutions you may have.