• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Distance Between Destructible and Unit

Status
Not open for further replies.

ndh

ndh

Level 8
Joined
Apr 21, 2012
Messages
344
Hey, I need a system that calculates the distance between 800 destructibles and 1 unit, then determines which destructible is closest to that unit. Any help/advice would be nice, can't seem to figure it out.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
I will write something up quick...
How are the destructables picked? In a region?

EDIT: Here is a vJASS system I wrote up. It checks each destructable in the specified rect (region in GUI). The system code:

JASS:
library DestructableEnum                // by Mr_Bean

    globals
        private destructable closest    // Stores current closest destructable.
        private real distance           // Stores distance of current closest destructable.
        private real unitX              // Stores x co-ordinate of checked unit.
        private real unitY              // Stores y co-ordinate of checked unit.
    endglobals

    private function ClosestDestrEnum takes nothing returns nothing
        local destructable d = GetEnumDestructable()
        local real dx
        local real dy
        local real dist
        
        if (GetWidgetLife(d) > 0.405) then
        
            set dx = GetDestructableX(d) - unitX
            set dy = GetDestructableY(d) - unitY
            set dist = SquareRoot((dx * dx) + (dy * dy))
        
            if (dist < distance) then
                set closest = d
                set distance = dist
            endif
            
        endif
        
        set d = null
    endfunction
    
    function GetClosestDestructable takes unit whichUnit, rect whichRect returns destructable
        set distance = 999999.0
        set closest = null
        set unitX = GetUnitX(whichUnit)
        set unitY = GetUnitY(whichUnit)
        call EnumDestructablesInRect(whichRect, null, function ClosestDestrEnum)
        
        return closest
    endfunction

endlibrary
And example usage:

  • Test Trig
    • Events
      • Player - Player 1 (Red) types a chat message containing -closest as An exact match
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg(GetDestructableName(GetClosestDestructable(udg_hero, bj_mapInitialPlayableArea)))
This prints the name of the closest destructable on the map to the unit stored in the hero variable.
 
Last edited:
Status
Not open for further replies.
Top