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 the
When considering collision handling, note the following:
- Collisions in Roblox can cause objects to move around. If that’s undesirable in your use case, disable
BasePart/CanCollide|CanCollideon one or both objects involved in the collision.
BasePart/TouchEnded|TouchEndedevents will still trigger on parts with
BasePart/CanCollide|CanCollidedisabled. However, you can disable
BasePart/CanTouch|CanTouchon objects which should never register a collision event.
BasePart|BasePartscan also use custom meshes. Check out
Enum/CollisionFidelity|CollisionFidelityto learn how collision detection can be fine-tuned to custom meshes.
Script below, when placed inside a part, shows how the
BasePart/Touched|Touched event can be connected to the custom
onPartTouched function 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.