Faster alternative to a .Touched event?

I’ve tried that. Perhaps, It’s the client which can’t handle it

I found a ModuleScript for .Touched events that could be helpful as well:

I’ve also had the same problem as OP: when there were eg 5 enemies all attacking the players there were so many touch events that performence got nuked.

The solution was to create my own system where I track the position of damage zones attachments in my code and simulate a sphere in that position. So then I check if 2 spheres intersect.
It requires some extra code, but it’s instanely fast because sphere-to-sphere intersection is the fasted intersection you can do.

If your collision shape is more complex you just use more spheres on each part.

I am able to now have 20+ (and even more) mobs attack a player in melee without any performance drops, while before when using Touch events the framerate would get destroyed even on a very powerful PC.

Also by using your own sphere-intersection code you don’t have to use any Roblox physics API, which makes everything even faster.

The only optimization you might need to do is to use some quad/octree or larger zones for a broadphase pass in case you have many spheres as the algorithm is O(n^2) as every sphere has to check every other sphere.

2 Likes