Activate ability when facing a certain angle?

Status
Not open for further replies.
Level 3
Joined
Jul 31, 2011
Messages
39
Is there a way to trigger an ability when facing a certain angle? For example, when facing directly south, give and take a 10 degrees margin of error on left and right...

*Look for my next post down below for a thumbnail....

I still can't figure it out... I am very noobish that after hours of searching for those values suggested I can't find it...

Guys, it may also work if suggest a trigger that is when facing a region...
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,243
You will need to define an angle range. To avoid the problem of how angles have the same value every 2pi radians, consider passing it through sin or cos and instead using a range of those values.

To define a number range, use comparision logic. This boolean can be used in a flow control statement like an if structure to restrict the running of code unless an angle is in a certain range.
 
Level 3
Joined
Jul 31, 2011
Messages
39
@mckill2009 Thank you. Let's simulate a pie, look for the attachment for the clearer picture...

@Dr Super Good Thank you for helping and sharing the knowledge...
You will need to define an angle range. To avoid the problem of how angles have the same value every 2pi radians, consider passing it through sin or cos and instead using a range of those values.

To define a number range, use comparision logic. This boolean can be used in a flow control statement like an if structure to restrict the running of code unless an angle is in a certain range.

May I use a radian instead of margin of error left and right as I've mentioned? 57.2957º south?

@Maker Thank you for being so specific to a newbie... your the best...
 

Attachments

  • angle.jpg
    angle.jpg
    97.6 KB · Views: 89
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • (Acos((Cos(((Facing of u) - 270.00))))) Less than 30.00
U is the unit whose facing you want to use. 30 is the tolerance in degrees, in your pic the tolerance is 15°. 270 is the angle to which you want to compare the facing to. 270° is south.

However you can drop the Acos and use a value between -1 and 1 for the less than part to improve efficiency a bit.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,243
WC3 uses radians for all trigometric opperations. GUI I think wraps them into degrees but underlying mechanics are in radians.

The reason for the conversion to Cos is because cos is a even function which converts an angle with an infinite range (due to itterative values) into a finite range. Where the angle 0, 2pi, 4pi etc all have the same angular value but different real values (so comparing them is difficult), when passed through cos they will give you a single unqiue value (1) which is much more managable and easy to compare to.

Sin can also be used when you need the properties of an odd function.

Angles in WC3 obey the same rules as those in mathematics. They start East and run anti-clockwaise to form a complete circle with 2pi radians.

South is thus 3/2*pi.

JASS reads unit facing as degrees (inconsistent scripting language lol). Thus to get unit facing in radians...
GetUnitFacing(u)*pi/180

As we want to measure the angle from south, we will need to move it so south is the origan.


Using the property of the even function Cos, one can get a value representing if the facing angle of u is in + or - of south (as the same offset in both directions returns the same value from Cos).

Cos(GetUnitFacing(u)*pi/180-3/2*pi)

To get if the angle of U is within 10 degrees of south, you have the facing of u measured from south so simply find the value of Cos(10degrees). As cos starts at 1( at0) and goes down to -1(at pi), you have to compare if the value from the unit facing is greater than the value constant.

Cos(GetUnitFacing(u)*pi/180-3/2*pi)>Cos(10degrees)

Now work out all the constants for efficiency...

Cos(GetUnitFacing(u)*0.01745329251994329576923690768489-4.7123889803846898576939650749193)>0.98480775301220805936674302458952

Obviously such precision for the constants is unnescescary. Trimming to 5 D.P. will probably give prety much maximum accuracy.

Cos(GetUnitFacing(u)*0.01745-4.71239)>0.98481

Obviously some error will have been introduced but then again that sort of error is present throughout the WC3 engine. The error certainly is so small that it is undetectable ingame.
 
Level 3
Joined
Jul 31, 2011
Messages
39
@Maker, I tried it yesterday on my own before I read your post and not successful because I have not used as much parenthesis as yours... thank you so much for posting actual triggering...

Have read your post yesterday... tempted to reply right away... but as a way of respect to the hive, I replied after a day instead - so as not to clog the thread with my own posts...



@Dr Super Good, thank you for elaborating... 0.01745 is the value of radian per degree right? From what I remember there are 6.28 radians per circle... I mostly got what you've suggested, thanks... From east right, what if i wanted to use the third arc or the third radian (that is west-northwest)?



@both actually south is just a representation of mine to make things simpler on perspective...
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,243
@Dr Super Good, thank you for elaborating... 0.01745 is the value of radian per degree right? From what I remember there are 6.28 radians per circle... I mostly got what you've suggested, thanks... From east right, what if i wanted to use the third arc or the third radian (that is west-northwest)?
Just remember that 180 degrees translates to exactly pi. Let a computer (via software such as the inbuilt calculator) solve an accurate approximation for you, it saves a lot of headaches.

As I mentioned, you shift the facing angle of the unit so that it becomes realitive to 0 (which represents the angle your comparing against) inorder for this to work. Think of it as distance, if you travel 2pi radians yet start at pi radians, the difference is 2pi-pi=pi radians. Basically converting 2 arbitrary points into 1 point offset against the origan (which represents the other point).

This is extreemly useful if you ever program Direct3D or OpenGL code as the vertex shader does this millions of times a second to build you virtual worlds.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,243
Cos(GetUnitFacing(u)*pi/180-3/2*pi)
This is pesudo code with real native names. It will throw a syntax error because "pi" is not defined. This was mearly used to demonstrate a step of how I worked out the final values.

Cos(GetUnitFacing(u)*0.01745-4.71239)>0.98481
This is a piece of JASS script which will evaluate to a boolean value.
true when unit u is facing within 10 degrees of south.
false when when unit u is not facing within 10 degrees of south.

Obviously its JASS as how else can you expect the WC3 JASS interpreter to run it ingame.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I don't understand what are you guys talking about, isn't he asking a very simple thing?(sorry I skipped some parts tl;dr. So feel free to kill me if I understood wrong.)

JASS:
function IsUnitFacingDegree takes unit u, real accuracy, real angle returns boolean
    local real face = GetUnitFacing(u)
    return face > angle - accuracy and face < angle + accuracy
endfunction

function IsUnitFacingSouth takes unit u, real accuracy returns boolean
    return IsUnitFacingDegree(u, accuracy, 270.00)
endfunction

//call function from somewhere
IsUnitFacingSouth(ourUnit, 15.00)

or gui

  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Facing of Unit) Greater than (270.00 - 15.00)
        • (Facing of Unit) Less than (270.00 + 15.00)
      • Then - Actions
        • -------- Unit is looking south --------
      • Else - Actions
 
Level 3
Joined
Jul 31, 2011
Messages
39
This is pesudo code with real native names. It will throw a syntax error because "pi" is not defined. This was mearly used to demonstrate a step of how I worked out the final values.


This is a piece of JASS script which will evaluate to a boolean value.
true when unit u is facing within 10 degrees of south.
false when when unit u is not facing within 10 degrees of south.

Obviously its JASS as how else can you expect the WC3 JASS interpreter to run it ingame.

Ahhh yes sir... I'm pertaining not on the formula but on the "cos(GetUnitFacing)" line...
 
Level 3
Joined
Jul 31, 2011
Messages
39
@Dr. correct me if I'm wrong...

Since I'm gonna use 15º instead of 10º... I have changed the tolerance...

The 3 in 3/2π (south) is in relation with the quadrant it is in... or if you prefer major points from north Counter-CW to east: 1/2π, π, 3/2π, 2π... That is where I would change the value when I am going to change to a different facing...

Thus,

South: Cos(GetUnitFacing(u)*0.01745-4.71239)>0.96593

West: Cos(GetUnitFacing(u)*0.01745-3.14159)>0.96593

North: Cos(GetUnitFacing(u)*0.01745-1.5708)>0.96593

East: Cos(GetUnitFacing(u)*0.01745-6.28318)>0.96593
 
Level 3
Joined
Jul 31, 2011
Messages
39
So you would rather use a slower solution? That does not really make any sense.

Also the solution using GUI was posted ages ago.

No sir... I'm not up for the slower and unreliable GUI... It's just for the reason that I'm just a noob and haven't ventured Jass yet... Frankly, I don't know Jass, and frankly, I am also not knowledgeable even on GUI... I have just started a week ago.. So even If i want to use Jass (I'm dying to, believe me), it's impossible for me make it done...
 
Status
Not open for further replies.
Top