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 entity.
Your entity must have Entity:EnableCustomCollisions enabled for this hook to work.
Your entity must also be otherwise "hit-able" with a trace, so it should have SOLID_OBB or SOLID_VPHYSICS be set (as an example), and it must have its collision bounds be set accordingly.
This hook is called for
anim type only.Arguments
4 Vector extents
Size of the hull trace, with the center of the Bounding Box being
0, 0, 0, so mins are -extents, and maxs are extents.Returns
1 table
Returning a
table will allow you to override trace results. Table should contain the following keys: (All keys fallback to the original trace value)
- Vector
HitPos- The new hit position of the trace. - number
Fraction- A number from0to1, describing how far the trace went from its origin point,1= did not hit.- Could be calculated like so :
Fraction = ( startpos + delta ):Length() / myCustomHitPos:Length()
- Could be calculated like so :
- 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_OBB entities.
Returning nothing or false allows the trace to ignore the entity completely.
Example
Example taken from lua/entities/widget_base.lua
Garry's Mod
Rust
Steamworks
Wiki Help