• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Moving units with triggers and map bounds

Status
Not open for further replies.
Level 7
Joined
Mar 24, 2008
Messages
184
I made a Check pathability function by using a unit with perma windwalk and no model thinking it would've been more efficient than Vexorian's one, just to discover that units with Windwalk can't go through items unlike normal units (that's why i had to add that "if"). Now, solved the items problem, i'm having another issue:
I've recently changed the map bounds to make the map bigger, and when the dummy unit tries to get over the old bounds, it stops moving (i'm using this function in a charge spell, so if i try to charge a unit that's in the new part of the map the unit stops moving). EDIT: meh...solved just while writing, but now i want to know why it doesn't work (see below)

JASS:
library Walkable initializer init
    globals
        integer pathcheckerid='e001'
        unit pathchecker
        boolean iteminrect=false
    endglobals
    
    function GetItems takes nothing returns nothing
            set iteminrect = true 
    endfunction

    function IsPointWalkable takes real x, real y returns boolean
        local integer i=70
        local rect r
        local boolean b
        call SetUnitPosition(pathchecker,x,y)
        set b=((GetUnitX(pathchecker)==x) and (GetUnitY(pathchecker)==y))
        if (b!=true) then
            set r=Rect(x-i,y-i,x+i,y+i)
            call EnumItemsInRect(r,null,function GetItems)
            set b=iteminrect
            set iteminrect=false
            call RemoveRect(r)
            set r=null
        endif
            return b
    endfunction

    function init takes nothing returns nothing
        set pathchecker=CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), pathcheckerid, 0, 0, 0)
        call IssueImmediateOrder( pathchecker, "windwalk" )
    endfunction
endlibrary

EDIT: I've just solved by changing

JASS:
        set b=((GetUnitX(pathchecker)==x) and (GetUnitY(pathchecker)==y))

With

JASS:
        set b=(RAbsBJ((GetUnitX(pathchecker)-x)+(GetUnitY(pathchecker)-y))<=1)

And by printing the x and y values everytime the function was called i discovered there's a 0.001 (sometimes 0.002) difference between the two values (GetUnitX(pathchecker) and x, same story for the y coord), but i don't understand why it had troubles only when in the situation i described above (trying to charge a unit that's in the part of the map i've recently added) and since i'm quite curious, i'd like to know why it didn't work
 
Status
Not open for further replies.
Top