TraceHull Issues

I have a melee weapon using TraceHull to detect if it’s hitting an entity. If i stand too close to the entity, then my tracehull doesn’t detect it. If i stand at a distance approximate to the hull trace length, it hits it.

Here’s the code:

[lua]local pos = self.Owner:GetShootPos()
local aim = self.Owner:GetAimVector() * 50

local tr = {}
tr.start = pos
tr.endpos = pos + aim
tr.filter = self.Owner
tr.mins = Vector(-20,-20,-20)
tr.maxs = Vector(20,20,20)

local trace = util.TraceHull( tr )
local ent = trace.Entity[/lua]

I’ve been fucking with the values and it seems like a shorter trace is more effective, but it still isn’t perfect. What values would be good to use for the maxs/mins/length, and how does valve do hit detection in their melee weapons?

Try something like…
tr.start = pos + self.Owner:GetAimVector() * -5
So the trace starts a bit behind the player.

Aren’t 5 units a bit much?

Okay well that slightly improved the hit detection. There are still cases where i’m standing right in front of an entity and the hull trace won’t detect it. Should i move it back even further?

I’ve used tracehull for weapons before, the problem I seemed to have was that the world would have priority over everything else, so if the enemy was near a wall it would return the hit entity as the world. Switching to ents.FindInBox helped a lot for me. That’s mainly the problem with traces, you get one single hit entity return.

What if i combined a normal trace with the hull trace for improved detection?

TraceHull is essentially just an ents.FindInBox that has the length of the trace and is really screwy in general. I would say avoid using it if you can. In most cases a trace alone will be fine for melee weapons, unless you want to check for a “swing area” in which case use ents.FindInBox.

Using both in conjunction wouldn’t really help you at all, imo.