ENTITY:TestCollision

From Garry's Mod
Jump to: navigation, search
 ENTITY:TestCollision( )

Contents

Description

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

NOTE Your entity must have Entity:EnableCustomCollisions enabled for this hook to work

Arguments

Vector startpos

Start position of the trace

Arguments

Vector delta

Offset from startpos to the endpos of the trace

Arguments

boolean isbox

Is the trace a hull trace?

Arguments

Vector extents

Size of the hull trace?

Returns

table

A table containing new HitPos, Fraction and Normal. Returning nothing allows the trace to ignore the entity completely.

Examples

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


Personal tools
Navigation