Raised This Month: $ Target: $400
 0% 

Best player in viewcone


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
MrDev
Member
Join Date: Sep 2005
Old 12-27-2006 , 08:45   Best player in viewcone
Reply With Quote #1

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.
MrDev is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode