• WaterLevel returns 0 for an npc even when completly submurged so long as it's on the ground
    3 replies, posted
I assume this is likely because the game is performing a volume check at the NPC's position (the very bottom of it's feet) which would be right on the edge of the water volume. Either way, I don't know of any other way to check for water at a point in the world. Any ideas?
Try with [url=http://wiki.garrysmod.com/page/util/PointContents]util.PointContents[/url]
Take a look at this: [url]https://github.com/Facepunch/garrysmod-issues/issues/631[/url] The last bit of code works great for players: [lua] function PLAYER:WaterLevel( ) local _pos1 = self:GetPos( ); local _halfSize = self:OBBCenter( ); local _pos2 = _pos1 + _halfSize; local _pos3 = _pos2 + _halfSize; if ( bit.band( util.PointContents( _pos3 ), CONTENTS_WATER ) == CONTENTS_WATER ) then return 3; elseif ( bit.band( util.PointContents( _pos2 ), CONTENTS_WATER ) == CONTENTS_WATER ) then return 2; elseif ( bit.band( util.PointContents( _pos1 ), CONTENTS_WATER ) == CONTENTS_WATER ) then return 1; end return 0; end[/lua] Just have it use the ENTITY meta-table instead of the PLAYER metatable.
[QUOTE=Loures;44703914]Try with [url=http://wiki.garrysmod.com/page/util/PointContents]util.PointContents[/url][/QUOTE] That's perfect! Thank you very much :) A minute ago I'd come up with a hacky solution that involved spawning a small prop inside of the npc and parenting it to the npc to be used as a water sensor. Your solution is much better!
Sorry, you need to Log In to post a reply to this thread.