Infinitegde
O.O
- Reaction score
- 86
Hey, I'm not 100% sure if anyone has posted this kind of snippet, but here it is.
Uses: - Basically if you want to decide if a unit is in front of another.
Why: Why can't you use normal Angle Between Points? Because, for one, it can return a negative angle! Ranges from 180- (-180).
Of course, you may think this is an easy fix, but, say, for example, the angle between points is 359, and the facing angle for the unit is 5. Say you wanted to decide if the point is in front, example, 120 degree field of vision. Then you would take the facing angle and add 60, and subtract 60, and see if the angle lies between. What happens? It doesn't work! Take a look
Ranges from 65 - (-55)... Now 359 is congruent to -1 which clearly lies within this range. BUT, it will not recognize it as so! (There is also another case, unit is in 1st quadrant, facing in 4th).
Due to these 2 cases, many people have become frustrated by this annoying problem.
Which is why I created this tiny function that acts as a fix.
Takes: real FacingAngle, real XoflocA, real YoflocA, real Xoflocb, real Yoflocb
Returns: real Angle
This function basically decides how it is suppose to convert the angle that the formula spits out!
Coded In Jass.
How to add to your map:
For Jass:
-I think you already know but, go to Trigger editor, click the map icon at the very top of list. Changes trigger frame, copy and paste the function into that frame. Set to a variable when you call it.
For GUI:
-Go to Trigger editor, click the map icon at the very top of list. Changes trigger frame, copy and paste the function into that frame.
-Create a new real variable.Example RealVar.(referred to as udg_RealVar)
-Need variables for the facing angle, and the two locations. (Unless you know a bit of Jass) Otherwise referred to as udg_Facing, udg_locA, and udg_locB respectively.
-Go to trigger and put in this text in a custom script:
And then use RealVar however you like!
How to use in Map:
-Reason its called AngleBetweenPointsFOV is because FOV stands for Field of Vision. It's specifically created for that.
-What to do with the real it returns: Well, let's see: FOV = 120 degrees
-Check if the real it returns is LESS than the facing of the unit + 60 (half the FOV)
-Check if the real it returns is GREATER than the facing of the unit - 60 (half the FOV)
If both these conditions are true, then the point is in front of the units 120 degree FOV.
- How else? You can make a backstab ability (as vypur85 said), and make it such that:
if the angle is GREATER than Facing of the unit + 135
if the angle is LESS than the Facing of the unit - 135
If both of these conditions are true that means the point is behind the unit in a 90 FOV.
-Very confusing isn't it? Well, use your imagination, because that's how it works.
Advantages:
-As many function calls as regular AngleBetweenPoints.
-Helps with the Field of Vision
Limitations:
Yes, there are a few pit falls with this small snippet. The only reason that I did not fix this, is because it would decrease the options of what you can do with this. Why? Well, it would involve making a system, that also takes the Field of Vision and then simply returns a boolean stating if it's in that area or not. To me, that is pretty lame... Which is why I have left it as such a small Snippet.
Now onto the ACTUAL limitations: Pretty much, if you try and compare it by adding values over 90 to the facing value, then, there is a chance for a bug. Two, if you add a value over 180, then it will bring a chance for another bug.
Other than that, it's lightweight, efficient, and pretty customizable.
Also, added a GUI version that shouldn't have any limitations. But. it takes the Field of Vision into account, like I said before, and decreases customization.
Here's the code:
Older Version: (Takes locations)
Here I have attached two versions of the map. The "test2" one is the Jass version, and the other one is the GUI Version.
Uses: - Basically if you want to decide if a unit is in front of another.
Why: Why can't you use normal Angle Between Points? Because, for one, it can return a negative angle! Ranges from 180- (-180).
Of course, you may think this is an easy fix, but, say, for example, the angle between points is 359, and the facing angle for the unit is 5. Say you wanted to decide if the point is in front, example, 120 degree field of vision. Then you would take the facing angle and add 60, and subtract 60, and see if the angle lies between. What happens? It doesn't work! Take a look
Ranges from 65 - (-55)... Now 359 is congruent to -1 which clearly lies within this range. BUT, it will not recognize it as so! (There is also another case, unit is in 1st quadrant, facing in 4th).
Due to these 2 cases, many people have become frustrated by this annoying problem.
Which is why I created this tiny function that acts as a fix.
Takes: real FacingAngle, real XoflocA, real YoflocA, real Xoflocb, real Yoflocb
Returns: real Angle
This function basically decides how it is suppose to convert the angle that the formula spits out!
Coded In Jass.
How to add to your map:
For Jass:
-I think you already know but, go to Trigger editor, click the map icon at the very top of list. Changes trigger frame, copy and paste the function into that frame. Set to a variable when you call it.
For GUI:
-Go to Trigger editor, click the map icon at the very top of list. Changes trigger frame, copy and paste the function into that frame.
-Create a new real variable.Example RealVar.(referred to as udg_RealVar)
-Need variables for the facing angle, and the two locations. (Unless you know a bit of Jass) Otherwise referred to as udg_Facing, udg_locA, and udg_locB respectively.
-Go to trigger and put in this text in a custom script:
JASS:
set udg_RealVar = AngleBetweenPointsFOV(udg_Facing,GetLocationX(udg_locA),GetLocationY(udg_locA),GetLocationX(udg_locB),GetLocationY(udg_locB))
And then use RealVar however you like!
How to use in Map:
-Reason its called AngleBetweenPointsFOV is because FOV stands for Field of Vision. It's specifically created for that.
-What to do with the real it returns: Well, let's see: FOV = 120 degrees
-Check if the real it returns is LESS than the facing of the unit + 60 (half the FOV)
-Check if the real it returns is GREATER than the facing of the unit - 60 (half the FOV)
If both these conditions are true, then the point is in front of the units 120 degree FOV.
- How else? You can make a backstab ability (as vypur85 said), and make it such that:
if the angle is GREATER than Facing of the unit + 135
if the angle is LESS than the Facing of the unit - 135
If both of these conditions are true that means the point is behind the unit in a 90 FOV.
-Very confusing isn't it? Well, use your imagination, because that's how it works.
Advantages:
-As many function calls as regular AngleBetweenPoints.
-Helps with the Field of Vision
Limitations:
Yes, there are a few pit falls with this small snippet. The only reason that I did not fix this, is because it would decrease the options of what you can do with this. Why? Well, it would involve making a system, that also takes the Field of Vision and then simply returns a boolean stating if it's in that area or not. To me, that is pretty lame... Which is why I have left it as such a small Snippet.
Now onto the ACTUAL limitations: Pretty much, if you try and compare it by adding values over 90 to the facing value, then, there is a chance for a bug. Two, if you add a value over 180, then it will bring a chance for another bug.
Other than that, it's lightweight, efficient, and pretty customizable.
Also, added a GUI version that shouldn't have any limitations. But. it takes the Field of Vision into account, like I said before, and decreases customization.
Here's the code:
JASS:
function AngleBetweenPointsFOV takes real Facing, real XoflocA, real YoflocA, real XoflocB, real YoflocB returns real
local real Angle = bj_RADTODEG * Atan2(YoflocB - YoflocA, XoflocB - XoflocA)
if (Angle < 0) and (Facing > 90) then
set Angle = Angle + 360
endif
if Angle < 90 and (Facing > 180) then
set Angle = Angle + 360
endif
return Angle
endfunction
Older Version: (Takes locations)
The difference is this one takes locations instead of reals:
JASS:
function AngleBetweenPointsFOV takes real Facing, location locA, location locB returns real
local real Angle = bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
if (Angle < 0) and (Facing > 90) then
set Angle = Angle + 360
endif
if Angle < 90 and (Facing > 180) then
set Angle = Angle + 360
endif
return Angle
endfunction