Hi devs! Here’s a quick overview of a new collision property for BaseParts.
BasePart.CanTouch
lets your determine if the part will trigger Touched
/TouchEnded
events on other BaseParts
with TouchTransmitters
.
- All
BaseParts
haveCanTouch
set toTrue
by default. - A
BasePart
'sTouched
orTouchEnded
event will only fire ifotherPart
hasCanTouch
set toTrue
. - You cannot set up a touch event on a
BasePart
that hasCanTouch
set toFalse
. Trying to do so will throw an error. If you setCanTouch
toFalse
on a part after aTouched
event is connected, the event will be disconnected (TouchTransmitter
removed).
Here’s a non-colliding part with a script telling it to turn green when touched. First, on the left, we drop parts that are CanTouch
. On the right, we drop parts that are not CanTouch
.
This behavior will also extend to BasePart:GetTouchingParts
. This function ignores all parts with CanCollide
set to False
, unless the caller part has a TouchTransmitter
(is listening for touch events). If that’s the case, all parts with CanTouch
set to False
will still be ignored.
Collision Groups
This collision logic is also being introduced to Collision Groups, which can be enabled with the Workspace.TouchesUseCollisionGroups
property. With this enabled, parts in different groups set to not collide, will ignore collisions and touch events. The CanTouch
property is ignored in this case (much like how the CanCollide
property is already ignored for parts in seperate non-colliding groups).
Performance
There’s a small performance gain on parts that have both CanTouch
and CanCollide
set to False
, as these parts will never need to compute any kind of part to part collisions. (They can still be hit by Raycasts and Region3 queries however).
(Note: Not all performance improvements are active yet, so you may not see a big difference for now)
Try it out now! Leave feedback or questions below!