Detecting units within a cone

bananaHUNT

You can change this now in User CP
Reaction score
55
I want to pick all units within a cone-shaped area in front of the caster.
This is to make a simple slash spell: You activate an ability, unit shows attack animation and slashes a small area in front of him for x damage (preferably his attack damage):

Code:
  ________
  \ area /
   \    /
    \  /
     \/
    unit

Now what would be the easiest way to do that?
 

Faust

You can change this now in User CP.
Reaction score
123
Gui would be messy and not very effective...
Make a trigger in your map.
Name it CONE.
Convert it to custom text.
Delete everything in it.
Copy this into it:

JASS:
library Cone
// whichGroup: the group the units will be added to
// xc, yc: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in radians
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in radians
// filter: the condition function to apply to the units in the sector.
function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing
    local group g = CreateGroup()
    local unit u
    local real x
    local real y
    local real x1
    local real y1
    local real x2
    local real y2

    call GroupEnumUnitsInRange(g, xc, yc, radius, filter)

    set angle = angle * 0.5
    set x1 = Cos(facing - angle)
    set y1 = Sin(facing - angle)
    set x2 = Cos(facing + angle)
    set y2 = Sin(facing + angle)

    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g, u)

        set x = GetUnitX(u) - xc
        set y = GetUnitY(u) - yc
        if y * x1 >= x * y1 and y * x2 <= x * y2 then
            call GroupAddUnit(whichGroup, u)
        endif
    endloop

    call DestroyGroup(g)
    set g = null
endfunction

// point: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in degrees
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
    local group g = CreateGroup()
    if filter == null then
        set filter = FILTER_True
    endif
    call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
    return g
endfunction

endlibrary


function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing

You have to use this line. I know it's JASS and bawwwwwww bawwwwwww, but it's not that difficult, and makes everything easier.
whichGroup: the group the units will be stored in
xc: X coordinates of the point of the cone
yc: Y coordinates of the same
facing: the angle of your casting unit
radius: the maximum distance
angle: the opening angle of the cone
filter: leave it as "null" (without brackets) to get all units in the cone.

Use it as this (example):

Trigger:
  • Custom Script: call GroupEnumUnitsInSector(G, GetUnitX(udg_caster), GetUnitY(udg_caster), udg_angle, udg_distance, udg_degree * bj_DEGTORAD, null)

Credits to AceHart
 

vypur85

Hibernate
Reaction score
803
Code:
Event
Condition
Actions
 Set Point1 = (Position of (Triggering unit))
 Set Real1 = Facing of (Triggering unit)
 Set Unitgp = Pick every unit within 600.00 range of Point1 matching....
 Unit group - Pick every unit in Unitgp and do multiple actions -
  Loop - Actions
    Set Point2 = (Position of (Picked unit))
    Set Real2 = Angle between [B]Point1[/B] and [B]Point2[/B]

    If - Condition
      Real2 Less than 0.00
    Then - Actions
      Set Real2 = Real2 + 360.00
    Else - Actions

    If - Condition
      Real2 Less than (Real1 + 120)
      Real2 Greater than (Real1 - 120)
    Then - Actions
      ----This (Picked unit) is within the cone region----
    Else - Actions

Something like the above. Untested though. But should be workable unless I missed something.

Edit:
My bad, mine is in fact for a 'sector' instead of a 'perfect triangle', as drawn by you in the first post.


> preferably his attack damage

Not possible.
 

Vicboy

Ultra Cool Member
Reaction score
44
I was doing something like this two days ago. >.<

If it were GUI, it would consist of using Angle between two points.

Check the unit's distance

Then

See if it's angle is infront of the unit or 20/-20 degrees away.
 

bananaHUNT

You can change this now in User CP
Reaction score
55
Thanks :D I used your GUI way vypur and it totally works !

Btw are there any leaks to remove? This will be the basic attack so its going to be used like hundreds of times (.2 cd). It was something with udg_RemoveGroup right?
 

Rainther

I guess I should write something of value here...
Reaction score
61
I think it is
call GroupClear(grp)
call DestroyGroup(grp)
set grp = null

to remove it completly, with "grp" being the variable. Call them in Custom Scripts.
 

vypur85

Hibernate
Reaction score
803
Code:
Event
Condition
Actions
 Set Point1 = (Position of (Triggering unit))
 Set Real1 = Facing of (Triggering unit)
 Set Unitgp = Pick every unit within 600.00 range of Point1 matching....
 Unit group - Pick every unit in Unitgp and do multiple actions -
  Loop - Actions
    Set Point2 = (Position of (Picked unit))
    Set Real2 = Angle between Point1 and Point2

    If - Condition
      Real2 Less than 0.00
    Then - Actions
      Set Real2 = Real2 + 360.00
    Else - Actions

    If - Condition
      Real2 Less than (Real1 + 120)
      Real2 Greater than (Real1 - 120)
    Then - Actions
      ----This (Picked unit) is within the cone region----
    Else - Actions
    Custom script:  call RemoveLocation (udg_Point2)
 Custom script:  call RemoveLocation (udg_Point1)
 Custom script:  call DestroyGroup (udg_Unitgp)

Leakless version. Notice which is inside/outside the loop.


call GroupClear(grp)
call DestroyGroup(grp)
set grp = null
Seems more like JASS to me. Though not sure if it needs null.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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