- Joined
- Mar 29, 2016
- Messages
- 688
IsLineWalkable v1.0b
This simple snippet allows you to check if there are any unwalkable paths such as cliffs, mapboundary and other obstacles such as some doodads between two points.
Requires:
TerrainPathability
Script
v1.0b
- Replaced the variables IsLineWalkable_X/Y with the functions GetLastWalkableX/Y
- Fixed a bug regarding the values of GetLastWalkableX/Y not being updated if IsLineWalkable returns true
v1.0
- First Release
This simple snippet allows you to check if there are any unwalkable paths such as cliffs, mapboundary and other obstacles such as some doodads between two points.
Requires:
TerrainPathability
Script
JASS:
library IsLineWalkable uses TerrainPathability/* v1.0b
________________
| |
| Written by AGD |
|________________|
|=====|
| API |
|=====|
function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean
- Checks if the line between points P1(x1, y1) and P2(x2, y2) does not contain any
any unwalkable coordinates including some doodads, cliffs, mapboundary, and other similar stuffs
function GetLastWalkableX takes nothing returns real
- Returns the value of the x-coordinate of the last walkable terrain when using IsLineWalkable
function GetLastWalkableY takes nothing returns real
- Returns the value of the y-coordinate of the last walkable terrain when using IsLineWalkable
*/
globals
///////////////////////////////////////////
// The path walkability check distance //
// interval. Lower value increases //
// precision but may cost performance. //
// Suggested value limit (10.00 - 25.00) //
///////////////////////////////////////////
private constant real checkInterval = 20.00
endglobals
//==============================================================================
globals
private real X = 0.00
private real Y = 0.00
endglobals
function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean
local real dx = x2 - x1
local real dy = y2 - y1
local real angle
local real x
local real y
if dx*dx + dy*dy < checkInterval*checkInterval then
if not IsTerrainWalkable(x2, y2) then
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return false
endif
else
set angle = Atan2(dy, dx)
set x = checkInterval*Cos(angle)
set y = checkInterval*Sin(angle)
loop
set x1 = x1 + x
set y1 = y1 + y
exitwhen x1 > x2 or y1 > y2
if not IsTerrainWalkable(x1, y1) then
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return false
endif
endloop
endif
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return true
endfunction
function GetLastWalkableX takes nothing returns real
return X
endfunction
function GetLastWalkableY takes nothing returns real
return Y
endfunction
endlibrary
v1.0b
- Replaced the variables IsLineWalkable_X/Y with the functions GetLastWalkableX/Y
- Fixed a bug regarding the values of GetLastWalkableX/Y not being updated if IsLineWalkable returns true
v1.0
- First Release
Last edited: