| 06-17-2009, 07:24 PM | #2 |
In the intersection point, make a third line which is orthogonal to the bisection line. Then make sure units are at the right side of that line. Like... Code:
k3 = (-1) * (a / facing) |
| 06-17-2009, 07:29 PM | #3 |
sin(a)/cos(a) = tan(a) |
| 06-17-2009, 07:32 PM | #4 |
It is more simple than that. Just set a variable to Atan2(y2-y1, x2-x1), and check if that value is greater than the facing angle of the unit - w/2 and less than face + w/2. And check if face + w/2 is greater than 360 degrees, or 2PI radians. If it is, subtract 360 or 2PI from the value. |
| 06-17-2009, 07:35 PM | #5 |
This should do it: JASS:function IsUnitInCone takes unit u1, unit u2, real w returns boolean // angle between units: local real a = bj_RADTODEG*Atan2(GetUnitY(u2)-GetUnitY(u1), GetUnitX(u2)-GetUnitX(u1)) // facing angle: local real b = GetUnitFacing(u1) // not sure if it returns degrees // delta angle: set a = b-a // norming angle: if a < 0 then set a = -a endif if a > 180 then set a = 360-a endif return a <= w endfunction |
| 06-18-2009, 09:17 AM | #6 | |
Thanks 0zxy0 and Opossum! That's an awesome solution :D Quote:
Yeah, it returns degrees. |
