Quote:
Originally Posted by whosyourdaddy
wont this work?
Code:
if( iOrigin1[0] <= iOriginCheck[0] <= iOrigin2[0] && iOrigin1[1] <= iOriginCheck[1] <= iOrigin2[1] && iOrigin1[2] >= iOriginCheck[2] >= iOrigin2[2] )
|
I don't think you understand what you're doing with this.
First, you should be consistent with your usage of '<='. You're using '>=' for the z dimension.
If you changed the '>=' to be consistent with the instances of '<=', then you'd be defining the boundaries of a box and checking if the player is inside this box. iOrigin1 is one corner of the box and iOrigin2 is the opposite corner of the box.
This is not your desired behavior.
Quote:
Originally Posted by whosyourdaddy
my origin arent floats eather so ya..... and theres something wrong with my logic i just cant see it
|
Look these up:
IVecFVec()
FVecIVec()
There's no problem converting between floats and integers.
Quote:
Originally Posted by whosyourdaddy
also can i do like get_distance(origin1[1],origin2[1])
|
No.
Code:
distance = abs( origin1[1] - orgin2[1] )
_____________________________________________ ______
You can use bugsy's code to run a traceline between the two points to see if it hits the player, but there are obvious limitations with this method. If there are obstacles along the traceline or if the origins are not located within the boundaries of the map, then it will fail.
I propose this simple test to see if the player is between the origins.
Code:
IsBetween(id, iPos1[3], iPos2[3])
{
new iPlayerPos[3]
get_user_origin(id, iPlayerPos)
new Float:fPlayerPos[3], Float:fPos1[3], Float:fPos2[3]
IVecFVec(iPlayerPos, fPlayerPos)
IVecFVec(iPos1, fPos1)
IVecFVec(iPos2, fPos2)
new Float:fPosVec[3], Float:fPlayerVec1[3], Float:fPlayerVec2[3]
xs_vec_sub(fPos1, fPos2, fPosVec)
xs_vec_normalize(fPosVec, fPosVec)
xs_vec_sub(fPos1, fPlayerPos, fPlayerVec1)
xs_vec_normalize(fPlayerVec1, fPlayerVec1)
xs_vec_sub(fPlayerPos, fPos2, fPlayerVec2)
xs_vec_normalize(fPlayerVec2, fPlayerVec2)
return !(xs_vec_dot(fPosVec, fPlayerVec1) < 0 || xs_vec_dot(fPosVec, fPlayerVec2) < 0)
}
This checks the angle between vectors to determine if the player is between the two origins.
I'm assuming that your desired behavior is to detect if a player is between two planes. That is, two parallel (non-intersecting) planes with a space between them. If the player is in this space between the planes, then he is, according to you, "between the origins".
So, we get the vector between the two test origins, V0.
Next, we get the vector between the first test origin and the player, V1.
Next, we get the vector between the second test origin and the player, V2.
If the angle between V0 and V1 is greater than 90 degrees, then the player is not in the space between the parallel planes. The same relationship exists for V0 and V2.
In the code, I'm using the cosine of the angle (or dot product of the vectors) rather than the actual angle, because it's an unnecessary calculation to get the actual angle. If the cosine is < 0, then the angle is greater than 90.
I suspect this method will work for all cases, and my tests indicate that it works. However, don't trust me. Test it for yourself.
_____________________________________________ ________
There's another way. You can test for the "k value" of a point with respect to a plane. A plane's k value can be calculated by doing the dot product of a point on the plane with the planes normal. See
here.
Anyways, here's the result:
Code:
IsBetween2(id, iPos1[3], iPos2[3])
{
new iPlayerPos[3]
get_user_origin(id, iPlayerPos)
new Float:fPlayerPos[3], Float:fPos1[3], Float:fPos2[3]
IVecFVec(iPlayerPos, fPlayerPos)
IVecFVec(iPos1, fPos1)
IVecFVec(iPos2, fPos2)
new Float:fNorm1[3], Float:fNorm2[3]
xs_vec_sub(fPos1, fPos2, fNorm2)
xs_vec_normalize(fNorm2, fNorm2)
xs_vec_sub(fPos2, fPos1, fNorm1)
xs_vec_normalize(fNorm1, fNorm1)
return !(xs_vec_dot(fPlayerPos, fNorm1) < xs_vec_dot(fPos1, fNorm1) || xs_vec_dot(fPlayerPos, fNorm2) < xs_vec_dot(fPos2, fNorm2))
}
It's slightly less code, I like it. The results for each function seem to agree, so you can use either one. I recommend the one with less code.
__________________