• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] How can I pick units from side of unit?

Status
Not open for further replies.

Ardenian

A

Ardenian

A unit has an x and an y coordinate, obviously.

If you want all unit on the right site of a unit, for example,
you pick every unit around a unit,
then check if its x coordinate is greater than the one from the origin unit, the unit you base the pick on, and if true, perform actions.
This way, you can filter out the sides you which to check.
 
Level 14
Joined
Nov 30, 2013
Messages
926
As Ardenian said above me.
In addition, if you don't want to accidently pick all the units from the right side (Which leads to the edge of the map.) of the specific unit for example, you can do something like this.
Code:
If (GetUnitX(GetEnumUnit()) < GetUnitX(Position of What unit) + (Radius))
 

Ardenian

A

Ardenian

Oh, yes, but in GUI you already choose a range, there it would not be necessary.
But good to now for Jass!

You could even add the condition to the unit pick itself, though I think it does not make a difference when it comes to performance, but only for readability ( where it is better to have a ITE after the unit pick).
 

Ardenian

A

Ardenian

For the left site it would be:
OriginUnit is the unit you pick other units around from.
TempUnit is the picked unit
  • Unit Group - Pick every unit in (Units within 512.00 of (Position of OriginUnit)) and do (Actions)
    • Loop - Actions
      • Set TempUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Conditions
          • (X of (Position of OriginUnit)) Greater than (X of (Position of TempUnit))
        • 'THEN'-Actions
        • 'ELSE'-Actions
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
It seems to me that streetpunk wants to pick units that are to the left or right from where unit is facing, not the general direction (west/east). If that is indeed that case, then the code Ardenian posted won't work, as it just checks if unit is to the west/east of caster instead of the left/right side of where the caster is facing.

To pick units which are to the left/right of where unit is facing, I think it may be worth giving a shot to actually pick all units nearby the the 'caster' and then mathematically calculate the distance of a point (the location of picked unit) to the formula of a normal to where the caster is facing. If the unit is within certain distance of the line (the normal) it should be to the left/right of the caster.

I drew a pic of what I mean
attachment.php

Here the black circle is the caster and the red circles are enemies.

given that wciii gives you access to unit's coordinates and its facing angle, you should be able to utilize it to calculate the normal to where the caster is facing. Since it is normal, it will always "aim" to the left/right of the caster. The last thing is to get the position of each nearby enemy and calculate the distance of the enemy to the normal. If the distance is small enough, the unit is indeed to the left/right of the unit.
 

Attachments

  • wc3a.png
    wc3a.png
    5.5 KB · Views: 139
Level 24
Joined
Aug 1, 2013
Messages
4,658
That wont work properly.

Imagine there are two units that are 300 units away from the normal you defined.
One of them is standing right behind your unit and the other is standing a big ass distance more to the east.
Now, both of them have 300 distance to the normal, which is lower than the maximum distance they are allowed to be considered left/right.
Now both are left/right of my unit, but the one that is just behind my unit shouldnt be.

I would do it using angle calculations.
Pick all units in X range of your unit (where X is the maximum range between the units)
Then you do an If/Then/Else to compare the angle between your unit and the picked unit.

if RAbsBJ(DenormalizeAngle(AngleBetweenCoordinates(x, y, GetUnitX(FoG), GetUnitY(FoG)) - direction)) < size then
This if statement can also be done in GUI.
The x and y are the position of your unit, the GetUnitX() and GetUnitY() are the position of the picked unit (FoG).
The size is the maximum allowed angle difference to call a unit left/right of your unit.
In your case, you can use 45 degrees. (45.00)
Direction has to be Facing of unit + 90 and Facing of unit - 90 so you have to do this twice.

Both RAbsBJ and AngleBetweenCoordinates can be done in GUI:
Math - Abs
Math - Angle Between Points

The "<" is code language for "less than" or "smaller than".

The DenormalizeAngle is a function I wrote myself... it is used to transform an angle so the value is between -180 and 180 (or -Pi and Pi for radians).
This function does not exist in GUI so you have to make it yourself.

  • Actions
    • Set TempLocation[0] = (Position of (Triggering unit))
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units within 500.00 of TempLocation[0]) and do (Actions)
      • Loop - Actions
        • Set TempLocation[1] = (Position of (Picked unit))
        • Set TempReal[0] = (Angle from TempLocation[0] to TempLocation[1])
        • Set TempReal[1] = (TempReal[0] + 90.00)
        • Set TempReal[2] = (TempReal[0] - 90.00)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Or - Any (Conditions) are true
              • Conditions
                • (Abs(TempReal[1])) Less than 45.00
                • (Abs(TempReal[2])) Less than 45.00
          • Then - Actions
            • -------- Unit is left or right. --------
          • Else - Actions
            • -------- Unit is neither left nor right. --------
        • Custom script: call RemoveLocation(udg_TempLocation[1])
    • Custom script: call RemoveLocation(udg_TempLocation[0])
Triggering unit at the top and 500 at the group creation should be replaced to what you need.
 
Status
Not open for further replies.
Top