Better Hitboxes

Currently I use Workspace::GetPartsBoundsInBox to find humanoids in a cuboid, but I’ve seen it may be taxing. Is there a more efficient way to do this?

2 Likes

EDIT: If you need every little increase in performance, use the params as I’ve sent. Otherwise, if you just want to implement it using someone elses stuff you can see below, the performance decrease/bloat from those should be negligible in most cases.

I had the same issue not long ago, and found OverlapParams to be quite useful
The cost of it, at least for me, all came from using a for loop to go through every single part in the bounds, and check if its a humanoid. The solution I use is to make a filter for all the RootParts I want to check for, reducing the loop count from 15+ per character nearby on top of terrain parts, building parts, etc., down to 1 per character nearby, nothing more.

So, if I understand correctly, something like this would be my recommended solution:

local Humans = {humanRootPart1, humanRootPart2, ...}
local oOverlapParams = OverlapParams.new()
oOverlapParams.FilterDescendantsInstances = {Humans}

--[[This would return only parts in your enemy models,
instead of literally every single part in the bounds]]
local nearbyParts = workspace:GetPartBoundsInBox(mainPart.Position, distance, oOverlapParams)

If you want any better solutions or help, you kinda have to post the code you want help with, or provide more details on what you’re looking for.

3 Likes

I recommend Muchacho’s hitbox, its extremely easy to use and very customizable.

1 Like

You should check out the Raycast Hitboxes module.