Collision filtering defines which physical objects collide with others. You can filter collisions by assigning BaseParts to collision groups or on a part-to-part basis with NoCollisionConstraint instances. One useful application of filtering is disabling character collisions.
Collision groups let you assign BaseParts to dedicated groups and specify whether or not they collide with those in other groups. Objects within non-colliding groups pass through each other without colliding. In the following video, the spinning objects are in different collision groups such that they collide with objects of another color but not with objects of their own color.
Collision Groups Editor
You can easily set up collision groups through Studio's Collision Groups Editor, accessible by clicking the Collision Groups button in the Model tab.
The editor functions in either Table View, which favors docking to the top or bottom of Studio, or a narrow List View which favors docking to the left or right side.
The editor opens with one Default collision group. All BaseParts automatically belong to this default group unless assigned to another group, meaning that they will collide with all other objects in the Default group.
To create a new collision group:
Click the Add Group button along the top of the editor panel.
Enter a new group name like Cubes and press Enter. The new group appears in both the left column and upper row of Table View, or in both columns of List View.
Repeat the process if necessary, choosing a unique and descriptive name for each group. Note that you can change a group's name during development by clicking in its field, or by selecting it and clicking the rename button.
Assigning Objects to Groups
Once you've created at least one custom collision group, you can assign objects.
Select one or more BaseParts that qualify as part of a collision group.
Assign them to the group by clicking the ⊕ button for its row.
In the Properties window, the new group is reflected under CollisionGroup.
Under default configuration, objects in all groups collide with each other. To prevent objects in one group from colliding with objects in another group, uncheck the box in the respective row/column.
In the following example, objects in the Cubes group will not collide with each other or with objects in the Doors group.
Collision groups can also be configured through scripting as follows:
Register empty collision groups via PhysicsService:RegisterCollisionGroup().
Assign objects to a group by setting their CollisionGroup property to the string name of the collision group, for example "Cubes".
Specify whether objects in groups collide by calling CollisionGroupSetCollidable(), providing the two collision groups and a boolean true (collidable) or false (non-collidable). If objects in the same group should or shouldn't collide with each other, use that group name for both the first and second parameters.Collision Group Setup1local PhysicsService = game:GetService("PhysicsService")23local cubes = "Cubes"4local doors = "Doors"56-- Register two collision groups7PhysicsService:RegisterCollisionGroup(cubes)8PhysicsService:RegisterCollisionGroup(doors)910-- Assign an object to each group11workspace.Cube1.CollisionGroup = cubes12workspace.Door1.CollisionGroup = doors1314-- Set cubes to be non-collidable with other cubes15PhysicsService:CollisionGroupSetCollidable(cubes, cubes, false)16-- Set cubes to be non-collidable with doors17PhysicsService:CollisionGroupSetCollidable(cubes, doors, false)18
To prevent collisions between two specific parts without setting up collision groups, such as between a vehicle's wheel and its chassis, consider the No Collision constraint. Advantages include:
- Configuration scripts are not required, so you can easily create and share models with customized collision filtering.
- Connected parts will not collide with each other, but they can still collide with other objects.
Disabling Character Collisions
Roblox characters collide with each other by default. This can lead to interesting gameplay, such as characters jumping on top of each other to reach specific areas. If this behavior is undesirable, you can prevent it through the following Script in ServerScriptService.
Script - Disable Character Collisions
1local PhysicsService = game:GetService("PhysicsService")2local Players = game:GetService("Players")34PhysicsService:RegisterCollisionGroup("Characters")5PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)67local function onDescendantAdded(descendant)8 -- Set collision group for any part descendant9 if descendant:IsA("BasePart") then10 descendant.CollisionGroup = "Characters"11 end12end1314local function onCharacterAdded(character)15 -- Process existing and new descendants for physics setup16 for _, descendant in pairs(character:GetDescendants()) do17 onDescendantAdded(descendant)18 end19 character.DescendantAdded:Connect(onDescendantAdded)20end2122Players.PlayerAdded:Connect(function(player)23 -- Detect when the player's character is added24 player.CharacterAdded:Connect(onCharacterAdded)25end)26