Collisions occur when virtual shapes intersect each other in the game world. In Roblox, these virtual shapes are
BasePart objects. What happens when they intersect is your decision through scripting.
When considering collision handling, note the following:
- Collisions in Roblox can cause objects to move around. If that’s not desirable based on your use case, disable
BasePart/CanCollide|CanCollideon one or both objects involved in the collision.
BasePart/TouchEnded|TouchEndedevents will still trigger, but the colliding objects’ momentum won’t be affected.
- To hide a part that detects collisions, like a region in front of a door which detects players entering a building, set its
BasePart|BasePartscan also use custom meshes. Check out
Enum/CollisionFidelity|CollisionFidelityto learn how collision detection can be fine-tuned to custom meshes.
Roblox will fire the
BasePart/Touched|Touched event when parts touch or intersect, even if they are set to not physically collide (
BasePart/CanCollide|CanCollide set to
false). This is useful for triggering events in a game such as opening trap doors, saving progress through an obstacle course with checkpoints, or changing the skybox of an area when you walk through different parts of the map.
Any part can be used to trigger
BasePart/Touched|Touched events. To use this event in your game, a function must be subscribed to it using
Script below, when placed inside a part, shows how the
BasePart/Touched|Touched event can be used to detect collisions with another part.
To detect if a player’s character has touched a part, find the parent of the colliding part and check if it contains a
Humanoid object. This script must be placed within the part that should detect collisions.
BasePart/Touched|Touchedevents fire multiple times for characters and other models, it may be because each part of the character (foot, lower leg, etc.) is triggering a distinct event. To manage this, you can include a
articles/Debounce|debouncesystem in your script.
Roblox also provides the
BasePart/TouchEnded|TouchEnded event which fires when a collision ends. This is useful to detect when two intersecting objects stop touching.