Snippet Angle Between Points Fix

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:
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
Here I have attached two versions of the map. The "test2" one is the Jass version, and the other one is the GUI Version.
 

Attachments

  • test2.w3x
    16.9 KB · Views: 258
  • Unit Facing Side V2.w3x
    20.7 KB · Views: 229

vypur85

Hibernate
Reaction score
803
You should actually give some example like Backstab or Damage Reduction at different angle etc etc. Probably you could also include GUI, to make it easier for all to understand. And the way you paragraph your snippet seems a little bit messy. Not sure why, but it really seem not neat to me :p. Probably you should justify the sentences here and there, add some bullets here and there, or bold/italise something here and there...
 

Kenny

Back for now.
Reaction score
202
Seems like this will come in handy for some people. I have already come up with a few ways to use it. As vypur85 said, maybe bold your subheadings or make them a different colour, it will give your presentation a better structure :). Also, it may be an idea to make another one of these snippets that uses reals instead of locations. Most JASS'ers out there prefer to stay away from locations, and will probably accept the two extra arguments if it means they do not have to use local locations. For example, if you are finding the angle between two units, you can either create then remove then null two locations, or use the GetUnitX(unit) and GetUnitY(unit) and not have to null them. That way if you have two, you are providing "the greatest good for the greatest number of people".

Anway +rep for the concept, as i said before this will definately come in handy for people who like "backstab" type spells. And i have seen many threads asking about how they are done.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
You sure the math used there is actually correct?


How is this going to help with, for example, me facing 1 degree and this returning 359 instead of the "usual" -1?
 
Reaction score
86
It does return -1. This checks for that specific case. If the facing angle is 1 then it will leave the angle alone because if you were to take the facing angle of the unit and subtract from it it would be negative and the angle would fall within the range.

Similarly, if the facing angle of the unit was 359, then it would add 360 to it.

So, simply, what it does is it takes the angle between the points and makes it comparable to the facing angle supplied.

So pretty much, in a nutshell, if the unit is facing the 3rd or 4th quadrant, and the angle is less than 90, then it will add 360 to it so it would be comparable with the facing example, which is, as an example, 359. So if the angle was 5 then it would return 365 in this case.
 

vypur85

Hibernate
Reaction score
803
I don't understand. Why not just use the condition if the angle between points is less than 0, then add 360. Isn't it easier?

Code:
Set Angle = Angle between Point1 and Point2
If then else
 Condition
  Angle Less than 0
 Then
  Set Angle = Angle + 360
 Else

Or is this what you do in your JASS trigger. Sorry, I'm a JASS-noob.
 
Reaction score
86
Kind of~ It depends on the facing angle of the unit. If the facing angle is 1 and the angle is -1, these two angles are only 2 degrees away right? But, if I just added 360 to it all the time, then it would become 1 and 359.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top