Hi all
I'm currently creating a plugin, and for that i need to create a drain life spell. Like the one in dota (pugna) or wow (warlock). Making the beam is no problem, nor is the damage dealing or animations. What bugs me it's the way I should detect which player will be the target of the spell.
The best would be to target the player most close to the players aim while ignoring the height (z). Like this
In the above illustration enemy2 would be the target because the angle to him is less than enemy1.
So i figured, Hey this is easy, it's just to:
1. Normalize the vector from current aim to player (aimvec)
2. Normalize the vector from each enemy to player (enemyvec)
3. Take the dot product between those, since (X dot Y) = |x||y|cos(¤)where ¤ is the angle between the vectors.
4. Find arccos(¤) and compare the angle
But nooo, this doesn't work; I'm pretty sure the problem lies in my understanding about the half-life geometry system.
If you substract 2 origins (points) you end up with a.. what? Origins in half-life seems to match points in geometry but angles seems to be different since they contain pitch, yaw and tilt. I've tryed to modify some code from Lord Of Destruction and it works.. sorta... but it's not always the best match and it sometimes selects the player behind me???
Here's the code
Code:
//Supposed :] - to find the angle betwene
//the CoreID and TargetID in the Distance d
public Float:Find_Angle(CoreID, TargetID, Float:Distance)
{
new Float:CoreAngles[3] = { 0.0, 0.0, 0.0 };
new Float:CoreOrigin[3];
pev(CoreID, pev_origin, CoreOrigin );
new Float:TargetOrigin[3];
pev(TargetID, pev_origin, TargetOrigin );
if (get_distance_f(CoreOrigin,TargetOrigin) > Distance)
{
return 9999.9
}
new anglemode:Mode = degrees;
// >> [ calculate Delta ]
new Float:DeltaOrigin[3];
for ( new i = 0; i < 3; i++ )
DeltaOrigin[i] = CoreOrigin[i] - TargetOrigin[i];
// >> [ calculate angle ]
CoreAngles[x] = floatatan( DeltaOrigin[z] / Distance2D( DeltaOrigin[x], DeltaOrigin[y] ), Mode ) ;
CoreAngles[y] = floatatan( DeltaOrigin[y] / DeltaOrigin[x], Mode );
//Why x?? Isn't this pitch??
( DeltaOrigin[x] >= 0.0 ) ? ( CoreAngles[y] += 180.0 ) : ( CoreAngles[y] += 0.0 );
//Angles from [-180:180] - We want the closets to our aim so take abs? Not sure about this either
if (CoreAngles[y] < 0.0)
CoreAngles[y] = CoreAngles[y]*(-1)
return CoreAngles[y]
}
I really need this for my mod. If anyone could post some suggestions/solutions/info or contact me @
[email protected] (msn) i would be very grateful.