Best Way to Make Hitboxes

So, the only way I think I can make hitboxes is to use an actual hitbox(a part with collision to false, and GetTouchingParts). But I really want to use magnitude. The game I am making is a building and breaking style game, where you have tools that break things. And it would be a pain to define every different object that is breakable to use .Magnitude. Is there a better way of doing this? Or, is there a way to use .Magnitude without defining every single object(as a variable).

All help is appreciated, and I will clarify if you don’t understand.

8 Likes

You could use a Region3 around the player as a “hitbox” and use Workspace:FindPartsInRegion3() to get any parts that are inside the region. The parts inside the region would be considered inside the hitbox of the player.

4 Likes

How would I use it, then? I’ve never really used Region3 before. The link gave me like, no info

Would it work like this:

Region3.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position) ?

1 Like
local Position = Vector3.new(0,0,0)
local Size = Vector3.new(0,0,0)

local Hitbox = Region3.new(Position-(Size/2),Position+(Size/2))
local PartsInRegion = game.Workspace:FindPartsInRegion(Hitbox) -- array

You would need to update the position of the region every frame so consider binding it to RunService.RenderStepped.

5 Likes

So, can I make a new hitbox each time the tool is activated instead? Will that work?

Yes that will work, you can create the region when the tool is activated and then check whatever parts are inside. Make sure you ignore the parts that are from your own character though.

1 Like

Technically speaking, the region3 would create a spherical hitbox, not a cubed one right? Thank you so much

No, the Region3 would create a cube-like hitbox, it would not be spherical.

Then, according to that, is it possible to make it spherical(sorry, I tend to ask questions so that I don’t have to make another thread)

And I got this error from this line:

Attempt to modify a readonly table

Region3.Size = Vector3.new(5,5,5) -- size of the region

There’s a module made by EgoMoose to do exactly that:

3 Likes

Sorry I fixed my code now. Should have said Hitbox instead of Region3

3 Likes

I have this error now:

Size cannot be assigned to

from the same line

Don’t make like this

local Region = Region3.new()
Region.CFrame = CFrame.new(0,0,0)
Region.Size = Vector3.new(0,0,0)

You’re trying to edit a readonly data.

local Position = Vector3.new(0,0,0)
local Size = Vector3.new(0,0,0)

local Region = Region3.new(Position-(Size/2),Position+(Size/2))
local PartsInRegion = workspace:FindPartsInRegion3(Region) -- Returns array with objects in region
6 Likes