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.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top