Garry's Mod Wiki

ENTITY:TestCollision

table ENTITY:TestCollision( Vector startpos, Vector delta, boolean isbox, Vector extents, number mask )

Description

Allows you to override trace result when a trace hits the entitys Bounding Box.

Your entity must have Entity:EnableCustomCollisions enabled for this hook to work
This hook is called for anim type only

Arguments

1 Vector startpos
Start position of the trace
2 Vector delta
Offset from startpos to the endpos of the trace
3 boolean isbox
Is the trace a hull trace?
4 Vector extents
Size of the hull trace?
5 number mask

Returns

1 table
Returning a table will allow you to override trace results. Table should contain the following keys, all optional:

  • Vector HitPos - The new hitpos of the trace
  • number Fraction - A number from 0 to 1, describing how far the trace went from its origin point, 1 = did not hit
  • Vector 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)
Returning nothing or false allows the trace to ignore the entity completely.

Example

Example taken from lua/entities/widget_base.lua

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

Example

Allows players to shoot through the entity, but still stand on it and use the Physics Gun on it, etc.

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

Page Links


Special Pages


Wikis

?

Render Time: 51ms

DB GetPage 3
Generate Html 25
SaveChanges (1) 8
Render Body 0
Render Sidebar 12