Collision Filtering

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

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.

Table View
List View

Creating Groups

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:

  1. Click the Add Group button along the top of the editor panel.

  2. 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.

    Table View
    List View
  3. 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.

  1. Select one or more BaseParts that qualify as part of a collision group.

  2. Assign them to the group by clicking the button for its row.

    In the Properties window, the new group is reflected under CollisionGroup.

Configuring Groups

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.

List View
Table View

Script Configuration

Collision groups can also be configured through scripting as follows:

  1. Register empty collision groups via PhysicsService:RegisterCollisionGroup().

  2. Assign objects to a group by setting their CollisionGroup property to the string name of the collision group, for example "Cubes".

  3. 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 Setup

    1local PhysicsService = game:GetService("PhysicsService")
    2
    3local cubes = "Cubes"
    4local doors = "Doors"
    5
    6-- Register two collision groups
    7PhysicsService:RegisterCollisionGroup(cubes)
    8PhysicsService:RegisterCollisionGroup(doors)
    9
    10-- Assign an object to each group
    11workspace.Cube1.CollisionGroup = cubes
    12workspace.Door1.CollisionGroup = doors
    13
    14-- Set cubes to be non-collidable with other cubes
    15PhysicsService:CollisionGroupSetCollidable(cubes, cubes, false)
    16-- Set cubes to be non-collidable with doors
    17PhysicsService:CollisionGroupSetCollidable(cubes, doors, false)
    18

Part-to-Part Filtering

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")
3
4PhysicsService:RegisterCollisionGroup("Characters")
5PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)
6
7local function onDescendantAdded(descendant)
8 -- Set collision group for any part descendant
9 if descendant:IsA("BasePart") then
10 descendant.CollisionGroup = "Characters"
11 end
12end
13
14local function onCharacterAdded(character)
15 -- Process existing and new descendants for physics setup
16 for _, descendant in pairs(character:GetDescendants()) do
17 onDescendantAdded(descendant)
18 end
19 character.DescendantAdded:Connect(onDescendantAdded)
20end
21
22Players.PlayerAdded:Connect(function(player)
23 -- Detect when the player's character is added
24 player.CharacterAdded:Connect(onCharacterAdded)
25end)
26