helping to add walkability checking to jump system by paladon

Status
Not open for further replies.
Level 12
Joined
Jul 17, 2013
Messages
544
since there isnt jump system that checks for terrain pathability i decided to edit the one by paladon.i alreday managed to make it so before spell is casted the game will check if targeted point is walkable but next step i need is to check if point that 0.03 triger moves unit to is walkable

1640736989772.png


i found the 0.03 trigger the problem is i dont know how to make this all work with the current existing conditions because the one i have is customs cript. the spell should also end instantly with all leaks cleared if its not walkable @Uncle can you take a look if u have time


1640737050953.png

the first part before spell is casted i did like that


i am attachting the map
 

Attachments

  • Jump [Paladon].w3x
    47.1 KB · Views: 11

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Create an Item and store it in an Item variable called PathingChecker. Make the item Invulnerable and Hidden.

Then create a Script and paste this code into it:
vJASS:
        function IsTerrainWalkable takes real x, real y returns boolean
            local real dX
            local real dY
            call SetItemVisible(udg_PathingChecker, true)
            call SetItemPosition(udg_PathingChecker, x, y)
            set dX = GetItemX(udg_PathingChecker)
            set dY = GetItemY(udg_PathingChecker)
            call SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
        endfunction

        function IsTerrainWalkableLoc takes location l returns boolean
            local real x = GetLocationX(l)
            local real y = GetLocationY(l)
            local real dX
            local real dY
            call SetItemVisible(udg_PathingChecker, true)
            call SetItemPosition(udg_PathingChecker, x, y)
            set dX = GetItemX(udg_PathingChecker)
            set dY = GetItemY(udg_PathingChecker)
            call SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
        endfunction
This checks for Buildings, Doodads, Cliffs, Boundaries, etc. and will return True or False depending on whether the terrain is walkable or not.

How to use it in GUI:
  • Set Variable TempPoint = (Position of (Triggering unit))
  • Custom script: set udg_WalkableBoolean = IsTerrainWalkableLoc(udg_TempPoint)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WalkableBoolean Equal to True
    • Then - Actions
      • -------- The terrain is walkable --------
    • Else - Actions
      • -------- The terrain is unwalkable --------
WalkableBoolean is a Boolean variable that you need to create. You can name it whatever you want, just make sure to update it's name in the Custom script if you change it.
 
Last edited:
Level 12
Joined
Jul 17, 2013
Messages
544
Create an Item and store it in an Item variable called PathingChecker. Make the item Invulnerable and Hidden.

Then create a Script and paste this code into it:
vJASS:
        function IsTerrainWalkable takes real x, real y returns boolean
            local real dX
            local real dY
            SetItemVisible(udg_PathingChecker, true)
            SetItemPosition(udg_PathingChecker, x, y)
            dX = GetItemX(udg_PathingChecker)
            dY = GetItemY(udg_PathingChecker)
            SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10;
        endfunction

        function IsTerrainWalkableLoc takes location l returns boolean
            local real x = GetLocationX(l)
            local real y = GetLocationY(l)
            local real dX
            local real dY
            SetItemVisible(udg_PathingChecker, true)
            SetItemPosition(udg_PathingChecker, x, y)
            dX = GetItemX(udg_PathingChecker)
            dY = GetItemY(udg_PathingChecker)
            SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10;
        endfunction
This checks for Buildings, Doodads, Cliffs, Boundaries, etc. and will return True or False depending on whether the terrain is walkable or not.

How to use it in GUI:
  • Set Variable TempPoint = (Position of (Triggering unit))
  • Custom script: set udg_WalkableBoolean = IsTerrainWalkableLoc(udg_TempPoint)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WalkableBoolean Equal to True
    • Then - Actions
      • -------- The terrain is walkable --------
    • Else - Actions
      • -------- The terrain is unwalkable --------
WalkableBoolean is a Boolean variable that you need to create. You can name it whatever you want, just make sure to update it's name in the Custom script if you change it.



can this walkability trigger be used by multiple spells and features at same time if it shares one item and one boolean variable? also does it matter if item is spawned or preplaced
 
Level 12
Joined
Jul 17, 2013
Messages
544
Create an Item and store it in an Item variable called PathingChecker. Make the item Invulnerable and Hidden.

Then create a Script and paste this code into it:
vJASS:
        function IsTerrainWalkable takes real x, real y returns boolean
            local real dX
            local real dY
            SetItemVisible(udg_PathingChecker, true)
            SetItemPosition(udg_PathingChecker, x, y)
            dX = GetItemX(udg_PathingChecker)
            dY = GetItemY(udg_PathingChecker)
            SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10;
        endfunction

        function IsTerrainWalkableLoc takes location l returns boolean
            local real x = GetLocationX(l)
            local real y = GetLocationY(l)
            local real dX
            local real dY
            SetItemVisible(udg_PathingChecker, true)
            SetItemPosition(udg_PathingChecker, x, y)
            dX = GetItemX(udg_PathingChecker)
            dY = GetItemY(udg_PathingChecker)
            SetItemVisible(udg_PathingChecker, false)
            // adjust 10 to modify the distance that's considered pathable
            return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10;
        endfunction
This checks for Buildings, Doodads, Cliffs, Boundaries, etc. and will return True or False depending on whether the terrain is walkable or not.

How to use it in GUI:
  • Set Variable TempPoint = (Position of (Triggering unit))
  • Custom script: set udg_WalkableBoolean = IsTerrainWalkableLoc(udg_TempPoint)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WalkableBoolean Equal to True
    • Then - Actions
      • -------- The terrain is walkable --------
    • Else - Actions
      • -------- The terrain is unwalkable --------
WalkableBoolean is a Boolean variable that you need to create. You can name it whatever you want, just make sure to update it's name in the Custom script if you change it.
\
also i did like you said but theres issue my unit can jumpinto places with low colission that normally he wouldnt be able to walk into so i came to conclussion the colission checking of item must be bigger. however its impossible to increase item colission as far as i know. i modyfited myself your function and replaced it with dummy unit but then unit cannot jump at all even if i set dummy colission to 1
function IsTerrainWalkable takes real x, real y returns boolean
local real dX
local real dY
call SetUnitPosition(udg_PathingChecker, x, y)
set dX = GetUnitX(udg_PathingChecker)
set dY = GetUnitY(udg_PathingChecker)
// adjust 10 to modify the distance that's considered pathable
return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
endfunction

function IsTerrainWalkableLoc takes location l returns boolean
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real dX
local real dY
call SetUnitPosition(udg_PathingChecker, x, y)
set dX = GetUnitX(udg_PathingChecker)
set dY = GetUnitY(udg_PathingChecker)
// adjust 10 to modify the distance that's considered pathable
return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
endfunction
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
As long as the Item exists before you try to use it in a trigger then it's fine. Just do this:
  • Events
  • Map initialization
  • Actions
  • Item - Create Boots of Speed at some point
  • Set Variable PathingChecker = Last created item
  • Item - Hide PathingChecker
  • Item - Make PathingChecker Invulnerable

If you want to adjust the range of the Pathing Checker, go into the code and change the 10 to a different number. You can see it written here:
vJASS:
// adjust 10 to modify the distance that's considered pathable
return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
See the two 10's, those are what you change.

And yes the system works for multiple spells (triggers) at the same time. It wouldn't be very useful if it didn't.
 
Level 12
Joined
Jul 17, 2013
Messages
544
As long as the Item exists before you try to use it in a trigger then it's fine. Just do this:
  • Events
  • Map initialization
  • Actions
  • Item - Create Boots of Speed at some point
  • Set Variable PathingChecker = Last created item
  • Item - Hide PathingChecker
  • Item - Make PathingChecker Invulnerable

If you want to adjust the range of the Pathing Checker you go into the code and change the 10 to a different number. You can see it written here:
vJASS:
// adjust 10 to modify the distance that's considered pathable
return (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
See the two 10's, those are what you change.
does the 10 equal to colission size 10 of unit? what would be the best number to unit of colission size 20?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I took the code from some old post a while back (there's like 20 different pathing checkers on Hive) so I'm not 100% sure.

What I do know is that there's no way to get the Collision Size of a unit and that's definitely not being done here.

The 10 is just some value that the creator went with. Try messing around with it, like using 5 or 20.

Edit: Also, make sure that the Point that you provide is where the unit is going to move, not where it is currently. You're testing the pathing of it's destination!
 
Last edited:
Level 12
Joined
Jul 17, 2013
Messages
544
I took the code from some old post a while back (there's like 20 different pathing checkers on Hive) so I'm not 100% sure.

What I do know is that there's no way to get the Collision Size of a unit and that's definitely not being done here.

The 10 is just some value that the creator went with. Try messing around with it, like using 5 or 20.

Edit: Also, make sure that the Point that you provide is where the unit is going to move, not where it is currently. You're testing the pathing of it's destination!
1640823930612.png
i tested, ifiincreased the numbers then it became worse. so i put the numbers to 1.0 then 0.1 and i still was able to jump into gaps imarked on photo
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Those gaps don't have any pathing so if you're testing the pathing there it's going to be considered walkable.

The way the code works is it moves the PathingChecker item to the Point that you provide. If the Point is Unpathable because something is in the way then the Item will get pushed to the nearest Pathable point. That's just how Units/Items work in Warcraft 3, for example, if you spawn a ground Unit on top of a building it will spawn next to the building instead. After that process is finished the code will check the distance between the Point and where the Item currently is. If the item moved a certain distance away then we know that the Point that you tried moving it to was Unpathable (something blocked it). Lastly, it returns TRUE if the item didn't move much and FALSE if the item moved too much, which tells us whether or not it was Pathable/Unpathable.

What I think you may want is some sort of advanced code that tests multiple points at once.

But you should show your trigger so I can see how you're using the system because there's a chance that you're making a mistake somewhere.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Here's something I came up with which might help. It's like IsTerrainWalkableLoc() but tests 3 Points instead of 1:
vJASS:
function IsPathingBlocked takes location l, real angle, real offset returns boolean
    // adjust 10 to modify the distance that's considered pathable
    local boolean success = false
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local real x2
    local real y2
    local real dX
    local real dY
    call SetItemVisible(udg_PathingChecker, true)
 
    // test first point
    call SetItemPosition(udg_PathingChecker, x, y)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // test second point
    set x2 = x + (offset * Cos(bj_DEGTORAD * (angle + 90.0)))
    set y2 = y + (offset * Sin(bj_DEGTORAD * (angle + 90.0)))
    call SetItemPosition(udg_PathingChecker, x2, y2)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x2 - dX) * (x2 - dX) + (y2 - dY) * (y2 - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // test third point
    set x2 = x + (offset * Cos(bj_DEGTORAD * (angle - 90.0)))
    set y2 = y + (offset * Sin(bj_DEGTORAD * (angle - 90.0)))
    call SetItemPosition(udg_PathingChecker, x2, y2)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x2 - dX) * (x2 - dX) + (y2 - dY) * (y2 - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // if we made it this far then the point is pathable
    call SetItemVisible(udg_PathingChecker, false)
    return true
endfunction
This is how you'd use it in the Jump trigger:
  • Custom script: set udg_WalkableBoolean = IsPathingBlocked(udg_JD_TempPoint[2], udg_JD_Angle[udg_JD_Integers[3]], 64)
64 is the Offset. Lowering it will make the "collision size" smaller. Increasing it will do the opposite.

Scientific breakdown:
ribbit.png


Edit: Updated code, more efficient now.
 
Last edited:
Level 12
Joined
Jul 17, 2013
Messages
544
Here's something I came up with which might help. It's like IsTerrainWalkableLoc() but tests 3 Points instead of 1:
vJASS:
function IsPathingBlocked takes location l, real angle, real offset returns boolean
    // adjust 10 to modify the distance that's considered pathable
    local boolean success = false
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local real x2
    local real y2
    local real dX
    local real dY
    call SetItemVisible(udg_PathingChecker, true)
 
    // test first point
    call SetItemPosition(udg_PathingChecker, x, y)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x - dX) * (x - dX) + (y - dY) * (y - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // test second point
    set x2 = x + (offset * Cos(bj_DEGTORAD * (angle + 90.0)))
    set y2 = y + (offset * Sin(bj_DEGTORAD * (angle + 90.0)))
    call SetItemPosition(udg_PathingChecker, x2, y2)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x2 - dX) * (x2 - dX) + (y2 - dY) * (y2 - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // test third point
    set x2 = x + (offset * Cos(bj_DEGTORAD * (angle - 90.0)))
    set y2 = y + (offset * Sin(bj_DEGTORAD * (angle - 90.0)))
    call SetItemPosition(udg_PathingChecker, x2, y2)
    set dX = GetItemX(udg_PathingChecker)
    set dY = GetItemY(udg_PathingChecker)
    set success = (x2 - dX) * (x2 - dX) + (y2 - dY) * (y2 - dY) < 10 * 10
    if success == false then
        call SetItemVisible(udg_PathingChecker, false)
        return false
    endif
    // if we made it this far then the point is pathable
    call SetItemVisible(udg_PathingChecker, false)
    return true
endfunction
This is how you'd use it in the Jump trigger:
  • Custom script: set udg_WalkableBoolean = IsPathingBlocked(udg_JD_TempPoint[2], udg_JD_Angle[udg_JD_Integers[3]], 64)
64 is the Offset. Lowering it will make the "collision size" smaller. Increasing it will do the opposite.

Scientific breakdown:
View attachment 392491

Edit: Updated code, more efficient now.
thanks, one last question i hope. some people said this system sucks. can u see anything wrong at it? as long as it doesnt make lags or memory leaks or errors i would say its fine
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
thanks, one last question i hope. some people said this system sucks. can u see anything wrong at it? as long as it doesnt make lags or memory leaks or errors i would say its fine
It looks old, outdated, inefficient, but it works and I doubt the performance gains would even be noticeable if you switched to something else.

If you're comfortable with it then use it.
 
Status
Not open for further replies.
Top