CollisionGroup Filtering For Touched Events

Currently, touched events will fire irrespective of the collision groups of the two parts involved. Now while this is not much of an issue from a game logic perspective - CollisionGroupsAreCollidable exists after all - it can create an extreme efficiency issue under some circumstances.

For example, working on a car game, you may wish to ‘ghost’ other players cars under some conditions, locally changing all the parts in the other car to a different CollisionGroup which does not collide with any other groups, allowing you to drive through the other car.

However, if you also have touch events attached to your car, for say collision sfx or other purposes, these touched events will cause massive physics slow down when your cars intersect, as the engine rapidly tries to process the thousands of collisions that are now happening every frame.


oh - oh no

I have also encountered similar issues in the past - zombies in a lot of Innovation games used touched events to spread infections, which caused significant slow-down when zombies interacted with players holding tools with lots of can-collide off parts or wearing custom haz-mat suits.

While changing the default behaviour could potentially break a lot of games, one potential option I would really like to see is to add a new method to BasePart that accepts a CollisionGroup and returns a touched event filtered to that specific collision group. This would hopefully solve the slow down issue in the above scenarios, and nicely complements the recent changes to ray-casting to accept collision groups.

39 Likes

Even better would be if we could use something similar to RaycastParams or OverlapParams for Touched events upon creation that would allow us to filter out or filter in exact parts we want colliding with this Touched event to speed things up. This is a life saver for those functions.

3 Likes

with the introduction of :Once() connections, we need this more than ever…

OnTouch = parent.Hitbox.Touched:Once(function(hit)
	if not hit:IsDescendantOf(script.Car.Value) then 
		Touching(hit) 
	else
		Touching() 
	end
end)

say for example this is in a car’s hitbox, and the problem is it would collide once with the car’s tires and never run again. There is no way to filter this out other than removing CanTouch from all 4 wheels, and doing so breaks other features that rely on .Touch for the wheels, like skidmarks.

But wait, isn’t that what this setting does? Or am I missing something here

waitWhat.

2 Likes

forgot that existed thanks

still, would be nicer if i had more explicit control outside of collisiongroups, since collisiongroups DO have a limit

2 Likes