Best player in viewcone
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 http://www.mortengryning.dk/Files/vec_explain.JPG 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:
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. |
Re: Best player in viewcone
HLSDK::combat.cpp
Code:
//=========================================================m_flFieldOfView = 0.5 // 90 degrees |
Re: Best player in viewcone
Thanks for the reply. I have reviewed the function myself and I must admit it didn't really work well. But that doesn't mean the function is wrong ;)
I noticed they didn't normalize the aimvec and I assume the fldot calculation is in radians? So if i want to extract the angle from all this I would have to add something like: new anglemode:mode = radians; float angle = floatacos(fldot,mode) and then compare the different angles? I could make the check first (fldot > 0.5) to make sure the player we're trying to find IS in the viewcone. However I think it was stated somewhere else that ViewCone didn't really work well? |
Re: Best player in viewcone
My function was only intended to set the clients aim vector to an origin regardless where this origin is.
btw : there is a much more efficient way Code:
but what you need is more like Code:
Of course you need to get the natives I used mod specific And for enemy2 you will need also need to add something like the smallest( floatabs(floatacos( dotp( playera, playerb ) ) )) as i did with the distance for dotp you may consult your favourite math formula collection^^ or use pm's xs library |
Re: Best player in viewcone
Thanks for the response. This would select the player closest to me IN my viewcone WHEN we can trace a line to him.. which is almost what i want. However if the player has 3 players in line of sight (viewcone+traceline) it should be obvious to him which one will be the target of the spell. The troubles im having is selecting the best target, i.e the target closest to his aim. I know how to do in teory but i can't get the code to work properly.
I see you're edited your post :) - And yes that's what i want, but im not sure what playera,b is? |
Re: Best player in viewcone
Quote:
|
Re: Best player in viewcone
upps playera is the <forward>vector of the players angles ( ang_to_vec ) aka his aiming vector
playerb is the enemyorigin - clientorigin ( connectionvector ) so you'll have to find the smallest floatabs(floatacos( dotp( forwardvector( client.angles ), enemy.origin - client.origin ) ) ) this should result in the closest enemy to your crosshair |
Re: Best player in viewcone
Thanks Lod and others
I got it to work with a modified sample of the c++ variant. This code will return a float where 0.0 is furthest away and 1.0 is closests to our aimline. If the player is not in the radius (distance) this function will return 0.0. Now all there is to do is to make a traceline check and people can begin to drain life :P Code:
|
Re: Best player in viewcone
Quote:
|
Re: Best player in viewcone
what you can do is use the get_distance_to_line stock by KoST (the line being from the player to where they are aiming) and then have it check everyone, and then just target the closest player.
Code:
#include <xs> |
| All times are GMT -4. The time now is 22:24. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.