Garry's Mod Wiki

Revision Difference

GM:ShouldCollide#511177

<function name="ShouldCollide" parent="GM" type="hook">⤶ <ishook>yes</ishook>⤶ <description>⤶ Called to decide whether a pair of entities should collide with each other. This is only called if <page>Entity:SetCustomCollisionCheck</page> was used on one or both entities.⤶ ⤶ Where applicable, consider using <page>constraint.NoCollide</page> instead - it is considerably easier to use.⤶ ⤶ <warning>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 <page>Entity:CollisionRulesChanged</page> on that entity immediately - **not in this hook.**</warning>⤶ ⤶ <bug issue="642">This hook can cause all physics to break under certain conditions.</bug>⤶ </description>⤶ <realm>Shared</realm>⤶ <predicted>Yes</predicted>⤶ <args>⤶ <arg name="ent1" type="Entity">The first entity in the collision poll.</arg>⤶ <arg name="ent2" type="Entity">The second entity in the collision poll.</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="boolean">Whether the entities should collide.</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>This should always return true unless you have a good reason for it not to.</description>⤶ <code>⤶ 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⤶ </code>⤶ ⤶ </example>