Garry's Mod Wiki

Revision Difference

util.TraceLine#546273

<function name="TraceLine" parent="util" type="libraryfunc"> <description> Performs a trace with the given trace data. <note>Clientside entities will not be hit by traces. When server side trace starts inside a solid, it will hit the most inner solid the beam start position is located in. Traces are triggered by change of boundary.</note> </description> <realm>Shared</realm> <args> <arg name="TraceData" type="table">The trace data to use. See <page>Structures/Trace</page></arg> </args> <rets> <ret name="" type="table">Trace result. See <page>Structures/TraceResult</page>. Can return `nil` if <page>game.GetWorld</page> or its <page text="physics object">Entity:GetPhysicsObject</page> is invalid. This will be the case for any traces done before <page>GM:InitPostEntity</page> is called.</ret> </rets> </function> <example> <description>Using a function callback as filter.</description> <code> local tr = util.TraceLine( { start = LocalPlayer():EyePos(), endpos = LocalPlayer():EyePos() + EyeAngles():Forward() * 10000, filter = function( ent ) if ( ent:GetClass() == "prop_physics" ) then return true end end } ) print( tr.HitPos, tr.Entity ) </code> <output>The trace will only hit prop_physics or world.</output> </example>⤶ ⤶ <example>⤶ <description>Insert a [wire ranger](https://github.com/wiremod/wire/blob/master/lua/entities/gmod_wire_ranger.lua) inside multiple solid sources.</description>⤶ ⤶ <output>⤶ <upload src="1bd91/8d93b11bded35a2.png" size="655599" name="image.png" />⤶ </output> ⤶ </example>