PhysicsService

Show Deprecated
Not Creatable
Service

PhysicsService primarily contains methods for working with collision groups which define whether a set of parts may or may not collide with parts in other collision groups. You can register a collision group through PhysicsService:RegisterCollisionGroup() and assign parts to it by setting those parts' CollisionGroup property to the name of the collision group.

Creating, deleting, and modifying collision relationships between collision groups is limited to server-side Scripts.

See Collision Filtering for usage details in Studio and within scripts.

Summary

Properties

Events

Methods


Returns whether the part is in the collision group.

CollisionGroupSetCollidable(name1: string, name2: string, collidable: boolean): nil  

Sets the collision status between two groups.


Returns whether the two groups will collide.


Creates a new collision group with the given name, and returns the ID of the created group.


Returns the ID of the collision group with the specified name.


Returns the name of the group with the corresponding ID.


Returns a table with info on all of the place's collision groups.


Returns the maximum number of collision groups.


Returns a table with info on all of the place's collision groups.

IkSolve(part: BasePart, target: CFrame, translateStiffness: number, rotateStiffness: number): nil  


LocalIkSolve(part: BasePart, target: CFrame, translateStiffness: number, rotateStiffness: number): nil  



Registers a new collision group with the given name.


Removes the collision group with the given name.


Renames specified collision group.


Sets the collision group of a part.


Unregisters the collision group for the given name.

Properties

Events

Methods

CollisionGroupContainsPart

Returns whether the specified part is in the specified collision group. This method will throw a runtime error in the following circumstances:

  • The specified group does not exist.
  • The specified part is not a BasePart.

Parameters

name: string
part: BasePart

Returns

CollisionGroupSetCollidable

Sets the collision status between two groups. This method will throw an error if either of the groups do not exist.

Parameters

name1: string
name2: string
collidable: boolean

Returns

CollisionGroupsAreCollidable

Returns whether the two specified collision groups will collide. This method will throw an error if either of the groups do not exist.

Parameters

name1: string
name2: string

Returns

CreateCollisionGroup

Creates a new collision group with the given name, and returns the ID of the created group.

Parameters

name: string

Returns

GetCollisionGroupId

This method returns the ID of the collision group with the specified name. It will throw an error if no group with the given name exists.

Parameters

name: string

The name of the collision group being retrieved.


Returns

The ID of the retrieved collision group, or nil if no such group exists.

GetCollisionGroupName

Returns the name of the collision group with the corresponding ID. This method will return nil if the group with the corresponding ID has not been named.

Parameters

name: number

Returns

GetCollisionGroups

Returns a table with info on all of the place's collision groups. Each value in the returned table is itself a table containing three members:

MemberTypeDescription
`id`integerThe ID of the group.
`mask`integerThe collision group's mask; only for internal use.
`name`stringThe name of the collision group.

Returns

GetMaxCollisionGroups

Returns the maximum number of collision groups the engine supports. This value is currently 32.


Returns

GetRegisteredCollisionGroups

Returns a table with info on all of the place's collision groups. Each value in the returned table is itself a table and containing two members:

MemberTypeDescription
`mask`integerThe collision group's mask; only for internal use.
`name`stringName of the collision group.

Returns

IkSolve

Roblox Script Security

Parameters

part: BasePart
target: CFrame
translateStiffness: number
rotateStiffness: number

Returns

IsCollisionGroupRegistered

Parameters

name: string

Returns

LocalIkSolve

Local User Security

Parameters

part: BasePart
target: CFrame
translateStiffness: number
rotateStiffness: number

Returns

RegisterCollisionGroup

Registers a new collision group with the given name. The name cannot be "Default" and it cannot contain the special characters / or ^.

Parameters

name: string

Returns

Code Samples

PhysicsService:RegisterCollisionGroup

1local PhysicsService = game:GetService("PhysicsService")
2
3local collisionGroupBall = "CollisionGroupBall"
4local collisionGroupDoor = "CollisionGroupDoor"
5
6-- Register collision groups
7PhysicsService:RegisterCollisionGroup(collisionGroupBall)
8PhysicsService:RegisterCollisionGroup(collisionGroupDoor)
9
10-- Assign parts to collision groups
11workspace.BallPart.CollisionGroup = collisionGroupBall
12workspace.DoorPart.CollisionGroup = collisionGroupDoor
13
14-- Set groups as non-collidable and check the result
15PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor, false)
16print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor)) --> false

RemoveCollisionGroup

Removes the collision group with the given name. If an invalid name is provided, this method will not do anything, although if the reserved name "Default" is provided, it will throw an error. If there are any parts in the collision group when it is removed, these parts will still maintain the same collision group ID. The physical behavior of parts in a removed group is undefined, so it is recommended to move any parts in a removed group to another group. This method will throw a runtime error in the following circumstances:

  • The name "Default" is provided.
  • The method is called from a client.

Parameters

name: string

Returns

RenameCollisionGroup

Renames the specified registered collision group, but does not rename the CollisionGroup property of parts that utilize the group. The first argument of this method is the name of the group to rename, the second argument is the new name for the group. If the specified group does not exist, this method will not do anything. The naming conventions for the new name follow the same rules as if the group was being created with PhysicsService:RegisterCollisionGroup().

This method will throw a runtime error in the following circumstances:

  • Invalid or empty name provided for either argument.
  • The method is called from a client.

Parameters

from: string
to: string

Returns

SetPartCollisionGroup

This method sets the collision group of the specified part to the group with the specified name. It is equivalent to setting the BasePart.CollisionGroupId, although calling this method is the recommended approach.

This method will throw a runtime error in the following circumstances:

  • The part parameter is not a BasePart instance.
  • The specified group does not exist.

Parameters

part: BasePart

The part being set.

name: string

The name of collision group that the part's collision group is being set to.


Returns

No return.

UnregisterCollisionGroup

Unregisters the collision group for the given name, with the following behaviors:

  • If an invalid name is provided, the method will not do anything.
  • If the reserved name "Default" is provided or if the method is called from a client, it will throw an error.
  • If there are any parts in the collision group when it is removed, those parts will still maintain the same collision group name. The physical behavior of parts in a removed group is undefined, so it's recommended to move any parts in a removed group to another group, such as the "Default" group.

Parameters

name: string

Returns