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 or ignore each other completely.
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 Setuplocal PhysicsService = game:GetService("PhysicsService")local cubes = "Cubes"local doors = "Doors"-- Register two collision groupsPhysicsService:RegisterCollisionGroup(cubes)PhysicsService:RegisterCollisionGroup(doors)-- Assign an object to each groupworkspace.Cube1.CollisionGroup = cubesworkspace.Door1.CollisionGroup = doors-- Set cubes to be non-collidable with other cubesPhysicsService:CollisionGroupSetCollidable(cubes, cubes, false)-- Set cubes to be non-collidable with doorsPhysicsService:CollisionGroupSetCollidable(cubes, doors, false)
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
local PhysicsService = game:GetService("PhysicsService")local Players = game:GetService("Players")PhysicsService:RegisterCollisionGroup("Characters")PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)local function onDescendantAdded(descendant)-- Set collision group for any part descendantif descendant:IsA("BasePart") thendescendant.CollisionGroup = "Characters"endendlocal function onCharacterAdded(character)-- Process existing and new descendants for physics setupfor _, descendant in pairs(character:GetDescendants()) doonDescendantAdded(descendant)endcharacter.DescendantAdded:Connect(onDescendantAdded)endPlayers.PlayerAdded:Connect(function(player)-- Detect when the player's character is addedplayer.CharacterAdded:Connect(onCharacterAdded)end)