HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Finding units in front of a unit

02-18-2008, 11:25 PM#1
Joker
Title pretty much covers it.
02-18-2008, 11:53 PM#2
MaD[Lion]
no it doesnt, wat do u mean by find
02-18-2008, 11:54 PM#3
Joker
You know how
Collapse JASS:
GroupEnumUnitsInRange
gets units at all angles. I want to know how to get units from only in front(the way it is facing) of him.
02-19-2008, 02:19 AM#4
Pyrogasm
You just have to filter them like so:
Collapse JASS:
library EnumInFront
    globals
        private real X1
        private real Y1
        private real AnglePlus
        private real AngleMinus
        private group Group
    endglobals

    private function Enum takes nothing returns nothing
        local unit U = GetEnumUnit()
        local real X2 = GetUnitX(U)
        local real Y2 = GetUnitY(U)
        local real Angle = Atan2(Y2-Y1, X2-X1)*57.2957

        if Angle < 0.00 then
            set Angle = Angle+360.00
        endif

        if (Angle>AnglePlus and Angle<AngleMinus) then
            call GroupRemoveUnit(Group, U)
        endif
    endfunction

    function GroupEnumInFrontOfUnit takes group G, unit U, real Radius, real Angle, boolexpr Filter returns nothing
        local real Facing = GetUnitFacing(U)

        set AnglePlus = Facing+Angle/2
        set AngleMinus = Facing-Angle/2
        if AngleMinus < 0.00 then
            set AngleMinus = AngleMinus+360.00
        endif
        set X1 = GetUnitX(U)
        set Y1 = GetUnitY(U)
        set Group = G

        call GroupEnumUnitsInRange(G, X1, Y1, Radius, Filter)
        call ForGroup(G, function Enum)
    endfunction
endlibrary
02-19-2008, 10:32 AM#5
Tide-Arc Ephemera
*twitches*

Pyrogasm... vJass? Unless my one month absence made me miss something, Pyrogasm + vJass = syntax error or somethin'...
02-19-2008, 01:19 PM#6
MaD[Lion]
then u should say: pick every unit in front of unit... not find... find is mroe like searching, but for wat.
Also in front means with how much angle variation ...
02-19-2008, 05:03 PM#7
Pyrogasm
I write vJASS for people... I even compile it manually :P