How to check if player is aiming at water?

Title is post.
How do I check if a player is aiming at water?


local TR = util.GetPlayerTrace( ply, ply:GetAimVector() )

if TR.MatType == MAT_SLOSH then
	--yey its water
end

I know traces, and I’m using self.Owner:GetEyetrace() to get it, I just need to know what to do with the trace object to check if player is aiming at water.

[editline]3rd September 2013[/editline]

Ty Nopari, should have refreshed before posting.

[editline]3rd September 2013[/editline]

Problem, MatType is always nil.
util.TraceLine(util.GetPlayerTrace( self.Owner )).MatType << That always gives 68 ==> MAT_DIRT, which is the mat under the water.

You’ll have to use util.TraceLine:



                local trace = {}
                trace.start = groundtrace.HitPos
                trace.endpos = trace.start + Vector( 0, 0, 1 )
                trace.mask = MASK_WATER

                local watertrace = util.TraceLine( trace )


What’s groundtrace?

local groundtrace = util.TraceLine{ start = ply:GetPos(), endpos = ply:GetPos()+ply:EyeAngles():Up()*-500, filter = ply }

Is that it? Found on google.

Also found this:

local watertrace = util.TraceLine{ start = ply:GetPos(), endpos = ply:GetPos()+ply:EyeAngles():Up()*-500, filter = ply, mask = MASK_WATER }

Will that work?

EDIT: Works :slight_smile: