Number of walls trace passed though

How exactly would I go about counting the number of brushes a trace has passed through?
I haven’t really tried much as I do not know what to do in order to make it ignore a certain brush but hit others.

Traces consider all brushes part of the “world.” Unless ignoreworld is set to true, it will always stop when it hits a brush – NoDraw and sky included, which can be seen with trace.HitNoDraw/HitSky.

So this means that I would have to check the material hit as opposed to just checking if it hit the world? I’d assume this wouldn’t work as well, or if it did it’d be very hacky as there could be other materials that it hits that are the same.

Can you give a specific example of what you’re trying to do? I’m confused what you’re asking

Alright, say I want to send a trace from one player to another and check how many walls the trace has passed through.

Here’s a bit of a strange example:
Player 1 Wall Wall Wall Player 2

The trace would have passed through three walls.

It honestly doesn’t need to be a trace if there is any other method of doing it, I just need to be able to retrieve the number of walls between two points.

Thanks for helping if you are :slight_smile:

Traces aren’t really setup to act like that. You would have to do something like this (pseudo-code):


local filter = {Player1, Player2}

local tr = { start = Player1:GetPos(), endpos = Player2:GetPos(), mask = MASK_SOLID, filter = filter}
local wallcount = 0

while (true) do

if ( tr.Fraction == 1 ) then
   -- No walls
   break;
elseif ( tr.Entity == game.GetWorld() ) then
   -- Wall
   wallcount = wallcount + 1
   repeat
      exit = tr.HitPos + NormalDir * testdist
      if ( bit.band( util.PointContents( exit, MASK_SOLID ) == 0 )) then
         tr = Retrace with this point as our start and Player2:GetPos() as end
      end
   until( we've found an empty point )
else
   -- Hit non-world entity blocking
   filter[#filter + 1] = tr.Entity
   tr = Retrace
end

end

Is there anything that would do this more efficiently?
Currently what I’m at is trying to make the trace ignore the world but make it still class it as a solid, which I don’t think is possible.

It would help to limit some things, what is the minimum and maximum allowed wall thickness? In case you got a few numbers it would certainly help improving the the thing.

I’m a bit late, but I have a question. What are you trying to do with this? I feel like there should be a better way that doesn’t use while loops or repeats

Not without some numbers like Zeh Matt said. Even CS:S limits wall penetration searches to a max distance for the sake of efficiency.