26.03.2015, 17:38
You could also use angles for a approximation
Both objects are imaginary viewing each other, if X and Y are in both "viewing angles" of the objects the player is between them (the viewing angle is given by the parameter degrees * 2)
Resulting that the detection area looks like a rhombus obj1<>obj2
Both objects are imaginary viewing each other, if X and Y are in both "viewing angles" of the objects the player is between them (the viewing angle is given by the parameter degrees * 2)
Resulting that the detection area looks like a rhombus obj1<>obj2
pawn Код:
stock IsBetweenXY(Float: X, Float: Y, Float: X1, Float: Y1, Float: X2, Float: Y2, Float: deg = 5.0) {
return (
(-deg <= (atan2(X2 - X1, Y2 - Y1) - atan2(X - X1, Y - Y1)) <= deg) &&
(-deg <= (atan2(X1 - X2, Y1 - Y2) - atan2(X - X2, Y - Y2)) <= deg)
);
}