-- P_BlockingWall: returns whether there's a wall blocking an object from moving a specified angle/distance
-- (NOTE: does NOT return WHICH wall was hit!)
-- You can put this in a separate script lump if you want! Call it from anywhere with P_BlockingWall(mobj, angle, maxdist)
local tester = nil -- Misc object used for testing
rawset(_G, "P_BlockingWall", function(mobj, angle, maxdist)
if not (tester and tester.valid) then -- Spawn a new one!
tester = P_SpawnMobj(mobj.x, mobj.y, mobj.z, MT_GARGOYLE) -- Has the best chance of not getting cleared on spawn
tester.flags = $1|MF_NOGRAVITY|MF_NOCLIPTHING -- Make sure it won't move or block things
tester.flags2 = $1|MF2_DONTDRAW -- Don't see the gargoyle! (can be commented out for testing if needed)
end
-- Match tester size to mobj size
tester.radius = mobj.radius
tester.height = mobj.height
P_TeleportMove(tester, mobj.x, mobj.y, mobj.z) -- Move tester to mobj's position
P_InstaThrust(tester, angle, maxdist) -- Misuse P_InstaThrust to easily get the distance to move
return not P_TryMove(tester, tester.x+mobj.x, tester.y+mobj.y, true) -- Return the inverse of P_TryMove (since it returns true on successful move, false on blocked)
end)