GM:ShouldCollide

From Garry's Mod
Jump to: navigation, search
 GM:ShouldCollide( )

Contents

Description

Called to decide whether a pair of entities should collide with each other. This is only called if Entity:SetCustomCollisionCheck was used on one or both entities.

This hook must return the same value consistently for the same pair of entities. If an entity changed in such a way that its collision rules change, you must call Entity:CollisionRulesChanged on that entity immediately - not in this hook.

Where applicable, consider using constraint.NoCollide instead - it is considerably easier to use.

NOTE This hook is predicted. This means that in singleplayer, it will not be called in the Client realm.

Arguments

Entity ent1

The first entity in the collision poll.

Arguments

Entity ent2

The second entity in the collision poll.

Returns

boolean

Whether the entities should collide.

Examples

Example

This should always return true unless you have a good reason for it not to.

function GM:ShouldCollide( ent1, ent2 )

    -- If players are about to collide with each other, then they won't collide.
    if ( IsValid( ent1 ) and IsValid( ent2 ) and ent1:IsPlayer() and ent2:IsPlayer() ) then return false end 

    -- We must call this because anything else should return true.
    return true

end


Personal tools
Navigation