• 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.

IsDistMoreThanObjectLength

Status
Not open for further replies.
Level 7
Joined
Feb 9, 2021
Messages
301
I wanted to ask someone to help me with the function that checks whether the remaining dash distance is bigger than the length of the not walkable path. The idea of this function is to have a check for knockback and dash spells, so they stop the movement if they can't cross a walkable path, similar to LoL. As far as I understand, the system should use the same algorithm in order to avoid problems: Bresenham Pathchecker. Unfortunately, I don't really understand it to rebuild another system.

Here is my previous attempt, but it does not account for NonWalkablePath properly:

JASS:
library IsRemaningDistMoreThanObject /*


    */uses /*
    
    */TerrainPathability
    
    
    globals
    
        private integer ACCURACY = 64
        
    endglobals
    
    function IsRemaningDistMoreThanObject takes real xMove, real yMove, real angle, real speed, real distLeft returns boolean 
        local real deltaX 
        local real deltaY 
        local real traveled 
        local real x 
        local real y 
        local real x1 = xMove + ModuloReal(xMove, ACCURACY)- ACCURACY/2
        local real x2
        if xMove > x1 then
            set x2 = x1 + ACCURACY
        else
            set x2 = x1 - ACCURACY
        endif
        
        if not IsTerrainWalkable(xMove, yMove) and not IsTerrainWalkable(x1, yMove) and not IsTerrainWalkable(x2, yMove) then
            set deltaX = Cos(angle * bj_DEGTORAD) * ACCURACY
            set deltaY = Sin(angle * bj_DEGTORAD) * ACCURACY
            set traveled = speed
            set x = xMove
            set y = yMove
            
            loop
                exitwhen traveled >= distLeft or (IsTerrainWalkable(x, y) and IsTerrainWalkable(x1, y) and IsTerrainWalkable(x2, y))
                
                set x = x + deltaX
                set y = y + deltaY
                set x1 = x + ModuloReal(x, ACCURACY)- ACCURACY/2
                if xMove > x1 then
                    set x2 = x1 + ACCURACY
                else
                    set x2 = x1 - ACCURACY
                endif

                set traveled = traveled + ACCURACY
            endloop
            
            debug call BJDebugMsg("[Shunpo] Distance Remaning" + R2S(distLeft))
            debug call BJDebugMsg("[Shunpo] Traveled Distance " + R2S(traveled))
            
            return traveled >= distLeft
        endif
        
        return false
    endfunction
    
endlibrary
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
Not sure about all that but one neat trick I've seen people do is use an Item to determine pathability. The basic idea is to have a hidden/invulnerable Item that you manage with a global variable. Whenever you want to test the pathing at a point you unhide and move this item to the point and then get the distance between the item and said point. If the item is not where it's supposed to be then you know that the point is unpathable and it's not safe to move the unit there.

This relies on Warcraft 3's pathing system to adjust the position of the item if necessary.
 
Last edited:
Level 7
Joined
Feb 9, 2021
Messages
301
Not sure about all that but one neat trick I've seen people do is use an Item to determine pathability. The basic idea is to have a hidden/invulnerable Item that you manage with a global variable. Whenever you want to test the pathing at a point you unhide and move this item to the point and then get the distance between the item and said point. If the item is not where it's supposed to be then you know that the point is unpathable and it's not safe to move the unit there.

This relies on Warcraft 3's pathing system to adjust the position of the item if necessary.
This is what TerrainPathability library is doing. However, there is a problem with this method for my purposes. The author of the algo goes about it here in detail: [vJASS] - [Snippet] IsPathBlockerInBetween
 
Status
Not open for further replies.
Top