Uncle
Warcraft Moderator
- Joined
- Aug 10, 2018
- Messages
- 7,866
So I have an ability that creates a unit at the target point of ability being cast.
I'm trying to prevent the unit from being created in unpathable areas but I can't seem to get it to work.
I tried testing the Pathing at the point before creating the unit:
TLDR, The function moves a test unit to 24 different points around the given x,y coordinates. After moving the unit I store it's current X/Y. The reason this works is because if the unit is moved somewhere unpathable then Warcraft 3's pathing system kicks in and pushes it to the nearest pathable location. Finally, I compare the distance between the original x/y coordinates and the stored values to find the closest pathable point. I then create my unit at that point.
This works, and it should work as many people have done this before.
However, the issue is more about an inconsistency. Check out the picture I attached, for whatever reason the left side of the cliff works as intended but the right side completely ignores my Pathing function. It's like the Pathing is turned off over there, but it's weird because the cliffs/doodads will still block movement.
Edit: I deleted some nearby cliffs and now neither side works... No clue what's going on.
I'm guessing this a Reforged issue?
Lua:
CreateUnit(Player(0), FourCC("h000"), x, y, 0)
I tried testing the Pathing at the point before creating the unit:
Lua:
function TestPoint(x, y)
local tester = CreateUnit(Player(0), FourCC("h002"), x, y, 0)
local ix
local iy
local dist
local angle = 0
local offset = 125
local loc = Location(x, y)
SetUnitPositionLoc(tester, loc)
RemoveLocation(loc)
UnitXTable[25] = GetUnitX(tester)
UnitYTable[25] = GetUnitY(tester)
--Check around the Unit for Pathable Locations
for i=1,24 do
angle = angle + 45
ix = x + offset * Cos(angle)
iy = y + offset * Sin(angle)
loc = Location(ix, iy)
SetUnitPositionLoc(tester, loc)
RemoveLocation(loc)
UnitXTable[i] = GetUnitX(tester)
UnitYTable[i] = GetUnitY(tester)
if i == 8 or i == 16 then
angle = 0
offset = offset + 125
end
end
--Find closest pathable X and Y
local getclosest = 99999
for i=1,25 do
ix = UnitXTable[i] - x
iy = UnitYTable[i] - y
dist = SquareRoot(ix * ix + iy * iy)
print(i, "Distance", dist)
if dist <= getclosest then
getclosest = dist
Winner = i
end
end
--Finish
local s = AddSpecialEffect("Abilities\\Spells\\Human\\DispelMagic\\DispelMagicTarget.mdl", UnitXTable[Winner], UnitYTable[Winner])
DestroyEffect(s)
print("Winner", Winner)
RemoveUnit(tester)
end
This works, and it should work as many people have done this before.
However, the issue is more about an inconsistency. Check out the picture I attached, for whatever reason the left side of the cliff works as intended but the right side completely ignores my Pathing function. It's like the Pathing is turned off over there, but it's weird because the cliffs/doodads will still block movement.
Edit: I deleted some nearby cliffs and now neither side works... No clue what's going on.
I'm guessing this a Reforged issue?
Attachments
Last edited: