Garry's Mod Wiki

Entity:SetCollisionGroup

  Entity:SetCollisionGroup( number group )

Description

Sets the entity's collision group.

Arguments

1 number group
Collision group of the entity, see COLLISION_GROUP enum

Example

Showcase function that produces reliable player-player nocollision for targets. First argument is any player entity, second is an optional number for min time. After min time elapsed, no-collision will turn off once we are not penetrating any players.

Contains no fail-saves or checks.

function ActivateNoCollision(target, min) local oldCollision = target:GetCollisionGroup() or COLLISION_GROUP_PLAYER target:SetCollisionGroup(COLLISION_GROUP_PASSABLE_DOOR) -- Players can walk through target if (min and (tonumber(min) > 0)) then timer.Simple(min, function() --after 'min' seconds timer.Create(target:SteamID64().."_checkBounds_cycle", 0.5, 0, function() -- check every half second local penetrating = ( self:GetPhysicsObject() and self:GetPhysicsObject():IsPenetrating() ) or false --if we are penetrating an object local tooNearPlayer = false --or inside a player's hitbox for i, ply in ipairs( player.GetAll() ) do if target:GetPos():DistToSqr(ply:GetPos()) <= (80*80) then tooNearPlayer = true end end if not (penetrating and tooNearPlayer) then --if both false then target:SetCollisionGroup(oldCollision) -- Stop no-colliding by returning the original collision group (or default player collision) timer.Destroy(target:SteamID64().."_checkBounds_cycle") end end) end) end end ActivateNoCollision(Entity( 1 ), 10)
Output: You can walk through the player for 10 seconds