Revision Difference
ENTITY:TestCollision#528148
<function name="TestCollision" parent="ENTITY" type="hook">
<ishook>yes</ishook>
<description>
Allows you to override trace result when a trace hits the entitys Bounding Box.
<note>Your entity must have <page>Entity:EnableCustomCollisions</page> enabled for this hook to work</note>⤶
<note>This hook is called for `anim` type only</note>⤶
<note>Your entity must have <page>Entity:EnableCustomCollisions</page> enabled for this hook to work.</note>⤶
<note>This hook is called for `anim` type only.</note>⤶
</description>
<realm>Shared</realm>
<predicted>No</predicted>
<args>
<arg name="startpos" type="Vector">Start position of the trace</arg>⤶
<arg name="delta" type="Vector">Offset from startpos to the endpos of the trace</arg>⤶
<arg name="startpos" type="Vector">Start position of the trace.</arg>⤶
<arg name="delta" type="Vector">Offset from startpos to the endpos of the trace.</arg>⤶
<arg name="isbox" type="boolean">Is the trace a hull trace?</arg>
<arg name="extents" type="Vector">Size of the hull trace?</arg>
<arg name="mask" type="number">The <page>Enums/CONTENTS</page> mask</arg>⤶
<arg name="mask" type="number">The <page>Enums/CONTENTS</page> mask.</arg>⤶
</args>
<rets>
<ret name="" type="table">Returning a `table` will allow you to override trace results. Table should contain the following keys, all optional:
* <page>Vector</page> HitPos - The new hitpos of the trace⤶
* <page>number</page> Fraction - A number from 0 to 1, describing how far the trace went from its origin point, 1 = did not hit⤶
* <page>Vector</page> Normal - A unit vector (length=1) describing the direction perpendicular to the hit surface⤶
Returning `true` will allow "normal" collisions to happen for `SOLID_VPHYSICS` and `SOLID_BBOX` entities (nextupdate)<br/>
* <page>Vector</page> `HitPos` - The new hitpos of the trace.⤶
* <page>number</page> `Fraction` - A number from `0` to `1`, describing how far the trace went from its origin point, `1` = did not hit.⤶
* <page>Vector</page> `Normal` - A unit vector (length=1) describing the direction perpendicular to the hit surface.⤶
Returning `true` will allow "normal" collisions to happen for `SOLID_VPHYSICS` and `SOLID_BBOX` entities.<br/>
Returning `nothing` or `false` allows the trace to ignore the entity completely.</ret>
</rets>
</function>
<example>
<description>Example taken from lua/entities/widget_base.lua</description>⤶
<description>Example taken from `lua/entities/widget_base.lua`</description>⤶
<code>
function ENT:TestCollision( startpos, delta, isbox, extents )
if ( isbox ) then return end
if ( !widgets.Tracing ) then return end
-- TODO. Actually trace against our cube!
return
{
HitPos = self:GetPos(),
Fraction = 0.5 * self:GetPriority()
}
end
</code>
</example>
<example>
<description>Allows players to shoot through the entity, but still stand on it and use the Physics Gun on it, etc.</description>
<code>
local sent_contents = CONTENTS_GRATE
function ENT:TestCollision( startpos, delta, isbox, extents, mask )
if bit.band( mask, sent_contents ) ~= 0 then return true end
end
</code>
⤶
</example></example>