Explosion-based hitboxes vs region3 hitboxes

so a while back i created a hitbox module that creates an explosion instance and uses it’s ‘hit’ event to gather and return all the parts within a certain radius but i learned recently that (with a bit of tweaking,) the exact same thing could be achieved with a region3 and FindPartsInRegion3.

what i want to know is: which of the two options is more optimal?

(i know that the answer might be embarrassingly obvious but i wanted to ask just in case.)

in the sample code for explosion.Hit showed a method of collecting all the hits into a table. In my opinion, region3 would be more efficient because it will do one sweep. Instead of Explosion.Hit event firing multiple times to collect each part hit.

im not sure there could be perks of using explosion.hit like grabbing instances with the radius of a sphere instead of region3 grabbing instances with a radius of a cube.(this isn’t important could just be speculation)

I would agree that Region3 is better since it was created for the purpose of finding objects inside a certain area. A downside is that Region3s are only aligned with the global coordinates so they can’t be rotated.

But if you want to find parts inside a rotated rectangular space you could do something similar to your explosion method by creating an anchored, invisible, noncollideable part and using GetTouchingParts().

local tempBrick = Instance.new("Part")
tempBrick.Anchored = true
tempBrick.CanCollide = false
tempBrick.Transparency = 1
tempBrick.Size = Vector3.new(10, 10, 40)
tempBrick.CFrame = CFrame.new(10, 0, 10) * CFrame.Angles(0, math.pi / 3, 0)
tempBrick.Touched:Connect(function() end)
tempBrick.Parent = workspace
local parts = tempBrick:GetTouchingParts()
tempBrick:Destroy()
1 Like

I haven’t done any tests, but I would assume Region3 hitboxes would be more efficient. The main problem with Region3 is that it’s ridged. You can only have non-rotated rectangular prisms. If you really need rotation, you should probably look into using EgoMoose’s Rotated Region 3 Module.

haha Birdelther already mentioned this

If you’re willing to sacrifice efficiency for simplicity, you could abuse GetTouchingParts to do something haxy like this:

local Part = Instance.new("Part")
Part.Shape= "Ball"
Part.Size = Vector3.new(5,5,5)
Part.Parent = workspace
Part.CFrame = CFrame.new(0,0,0)

Part.Touched:Connect(function() end) -- done to create a TouchInterest

local TouchingParts = Part:GetTouchingParts()

I made a custom explosion system using the above method and I’ve yet to run into any issues. The system easily supported hundreds of explosions. The beauty of the above method is that it works with any shape.