Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
Good day, i want to select units in a cone shape in front of my hero using angels ( i used breath of frost buffs to select units but it does not feet my needs )
GUI pleas Thanks
You cannot select units in cone shape, however you can select all nearby units and check their position towards the caster. If the angle between caster and unit in unit group is within certain radius, that unit should be in the in what would be the cone shape.
Another problem that raises here is that the GUI action for finding out angle between points doesn't get from 0° to 360°, but from 180° to -180°.
For most efficient way via gui, you will need a few variables and custom scripts (these are needed to prevent memory leaks and all you have to do with them is you basically copy what I write)
Variables:
unit1, unit2 = unit variables
loc1, loc2 = point variables
angle = real variable
The trigger in hidden tabs finds every unit which is alive, is enemy to the caster and is in 90° cone in front of caster (90° = 45° to left and 45° to right from where the caster is looking).
You may want to get the angle of caster differently, depending on how your spell behaves.
a) If your spell targets enemy unit, and you want to damage everyone in cone, but from the angle "from caster to targeted unit", then you will need to do this:
Actions
Set unit1 = (Triggering unit)
Set loc1 = (Position of unit1)
Set loc2 = (Position of (Target unit of ability being cast))
Set angle = (Angle from loc1 to loc2)
Custom script: call RemoveLocation(udg_loc2)
Custom script: set udg_loc2 = null
I got the angle between caster and target by getting position of those units and saving the angle into variable. Then I remove only the second location - loc2, because I will still need loc1 when I pick all nearby units into unit group, just like in previous trigger.
b) If you don't target a unit, but you target point, then the approach will be very similar:
Actions
Set unit1 = (Triggering unit)
Set loc1 = (Position of unit1)
Set loc2 = (Target point of ability being cast)
Set angle = (Angle from loc1 to loc2)
Custom script: call RemoveLocation(udg_loc2)
Custom script: set udg_loc2 = null
Instead of getting position of the target, I immediately got the target point of ability being cast and saved it into loc2.
(Acos((Cos((angle - (Angle from loc1 to loc2)))))) Less than or equal to 45.00 Thats what i seeked for 6 hours !!
Fus Ro Dah !!! Thanks man it works perfectly
Thanks Icemanbo, i tried it before i was able to get units from all angels except the ones from -45° to 45° due to the jump from 360 to 0, so i used cosinus but it gave me weired results.
I don't think that will work well.
I'm not sure atm how "facing of (unit)" is handled, but the function "angle from p1 to p2" returns angle ranging between -180 to +180, while I believe "facing of unit" returns angle ranging between 0 to 360.
If I am correct, you would get problems if you were to pick units in cone that faces the general direction of 180°, as the facing +-45° would still get incorrect values in some cases.
(Cos((angle - (Angle from loc1 to loc2))) Greater than or equal to (Cos(45.00))
Which optimizes to...
(Cos((angle - (Angle from loc1 to loc2))) Greater than or equal to 0.707
Saves on a function call. It works because of the symmetry of Cos around 0 degress. In fact you can use this approach to get deviation from 180 as well with less than or equals to a negative number. If you want deviation from a right angle (90/270) you need to use Sin.
Elaborate? In what way were they weird. Do not just say "it did not work", I want to know the actual values being returned compared with the expected values.
first i used :
if UnitAngel is between (HeroAngel - 45) and (HeroAngel + 45 ) but it did work wrong because of units between 315° and 45° around the Hero so i used cosinus, if Cos[UnitAngel] is between Cos[(HeroAngel - 45)] and Cos[(HeroAngel + 45 )] but it started skipping units most of the times or at some angels selecting no unit.
and then i used Acos as nichilius told me and it did work perfect, so maybe comparing small reals in WC3 engine is not that precise ^^
This makes no sense anyway and is not what I told you to do.
1. Get angle of picked unit with respects to origin of cone.
2. Subtract this angle by the angle of cone.
3. Get the Cos of this angle.
4. Compare if result is greater than the cos of half the cone angle).
Cos is a symmetric function so if the unit is 179 degrees away from the angle of the cone in either direction the cos on 179 or -179 is the same.
Cos runs from 1 at 0 degrees to -1 at 180 degrees. Combined with the symmetry above you can test if an angle range is met with respects from 0 or -180 by inverting the comparison. For angles with respect to 90 and 270 you need to use Sin as that is symmetric there.
You have the angle of the unit with respects to the cone origin from 1.
You then have your angle of the cone (if the cone was directly in front of a unit this would be that unit's facing).
You then get the angle of the unit (step 1) and subtract it by the angle of the cone (whatever you define your cone to face).
The result is an angle that represents the difference between the cone facing and the unit. If this angle is too large the unit will be outside the cone.
The other steps are just analysing this angle to make sense of it. Step 3 converts it from an angle into the cosine of the angle which is easier to analyse due to the symmetry and finite range (unlike the angle which has multiple different values that are technically equivalent). Step 4 tests this result to get if the unit was inside the cone.
There's a lot simpler way you can do this, with some help from a damage detection system. Simply use a cone spell that applies a debuff, such as breath of fire, then catch the event by detecting when a unit takes damage, and checking if it has the debuff of the spell you used; if it does, then it has been hit by the cone spell, and you can apply further actions from that point. Much simpler, and doesn't involve complicated maths. Though, be sure to remove the debuff in your trigger.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.