I'm trying to make a weapon that shoots through walls. I have a trace in the middle of the action that checks if we've hit the same entity so one bullet doesn't hit one entity several times as it passes through.
[code]
Msg(tr.HitPos.x .. " ")
Msg(tr.StartPos.x .. "\n")
self.dist = self.dist+1
trace = {}
trace.StartPos = tr.HitPos + (1-tr.Fraction)*10*self.dir
trace.EndPos = tr.StartPos + 10*self.dir
trace.Mask = MASK_SHOT
Msg(trace.StartPos.x .. " ")
Msg(trace.EndPos.x .. "\n")
tr = util.TraceLine(trace)
Msg(tr.HitPos.x .. " ")
Msg(tr.StartPos.x .. "\n")
[/code]
is the trace. Here's the output for the first iteration, which makes the remainder nonsensical. Importantly, the last pair (the results of the trace) are always 0.
[url]http://i.imgur.com/oXDDwa0.png[/url]
The first tr is determined via the bullet callback. self.dir is calculated by doing tr.HitPos-tr.StartPos, and then normalizing.
Why is a trace always telling me it's hitting and starting at the origin, even when the startpos is nowhere near it?
[url]http://wiki.garrysmod.com/page/Structures/Trace[/url] Read carefully. There's no such thing as StartPos in the trace table you pass as argument to util.TraceLine, only in trace result
Welp. Never noticed that before.
Sorry, you need to Log In to post a reply to this thread.