HitboxClass v2.0 | A Powerful OOP Hitbox Module

HitboxPlus - a hitbox module for combat games

HitboxPlus

Hey everyone,

I’ve been working on the hitboxes for a combat game, and after rewriting the same stuff a few times I ended up turning it into its own module. It’s free, so I figured I’d share it.

Get the module: https://create.roblox.com/store/asset/135948985088815/HitboxModule-v2

What it does

You give it a shape and a root, and it tells you which characters are inside. That’s the core of it. The rest is the stuff that kept biting me in an actual game:

  • A punch hitbox has to follow the player while they lunge, not stay where the swing started.
  • Fast attacks can skip right past someone between two checks, especially when the server lags a bit.
  • Each target should get hit once per swing, not once per frame.
  • Everything has to clean itself up if the player dies or leaves mid-attack.

HitboxPlus deals with all of that, so the code on your end is just “make a hitbox, listen for hits”.

Quick example

local HitboxPlus = require(path.to.HitboxPlus)

local hitbox = HitboxPlus.new("WeldedBox", {
	root = character.HumanoidRootPart,
	offset = CFrame.new(0, 0, -2), -- 2 studs in front of the character
	size = Vector3.new(4, 5, 3),
	duration = 0.25,
	interval = 0, -- check every frame
	IgnoreCharacters = { character },
})

hitbox.OnHit:Connect(function(target, part)
	print("hit", target.Name)
end)

hitbox:Start()

Set debug = true if you want to see the box while you’re tuning it.

Hitbox types

  • Box / Ball check once, right away.
  • TimedBox / TimedBall keep checking for a while, staying where they started.
  • WeldedBox / WeldedBall / WeldedCylinder keep checking and follow the root around. This is what I use for melee.
  • InPart uses a part’s exact shape, Magnitude checks real distance from the center, and Cylinder is… a cylinder.

Hit modes

  • Weak (default): each character gets hit once for the whole hitbox. One swing, one hit.
  • Strong: every part, every check.
  • Cooldown: each character at most once every few seconds. Nice for things like a fire zone you stand in.

The part I’m happiest with: sweeping

Welded boxes cover the whole distance they moved since the last check, not just where they ended up. Before this, a fast dash or a laggy server frame would sometimes carry the box straight through someone and the hit just wouldn’t register. Now it does. It’s on by default; turn it off with sweep = false if you don’t want it.

Other options

  • velocityPrediction aims the box a bit ahead of where the root is moving.
  • dotProductFilter only counts targets inside a cone, e.g. only in front of you.
  • proportional sizes the box from the root part’s own size.
  • blacklistParts lets you ignore specific parts, not just whole characters.
  • hitboxId tags hitboxes so you can cancel them together, like when a player gets stunned mid-combo:
HitboxPlus.ClearHitboxesWithId("Punch_" .. player.UserId)

There’s also GetHitboxesWithId, GetActiveHitboxCount, ClearAllHitboxes, and SetTargetContainer if your characters live in a folder like workspace.LivingThings.

Performance

I tried to keep it cheap, since combat games end up running a lot of these:

  • All hitboxes share one Heartbeat, and it disconnects when none are running.
  • Checks reuse their tables instead of making new ones every time.
  • Cylinders reuse one part, and it won’t show up in your other raycasts or queries.
  • Debug mode moves a single box around instead of spawning a new one every frame.

What’s in the package

  • HitboxPlus - the main module
  • SpatialHitbox - the raw queries it’s built on (box, sphere, in-part, magnitude, cylinder, raycast). You can use these on their own too.
  • It needs GoodSignal next to it for the OnHit event.

Everything is typed. If you pass something wrong, like a missing size, it errors as soon as you create the hitbox, so you catch it while building instead of in the middle of a fight.


That’s pretty much it. If you find a bug or have an idea, let me know below. And if you end up using it in something, I’d love to see it!

30 Likes

You forgot to make the game public

2 Likes

Looks promising, will try it out!

Click the 3 dots and download a copy, or just edit the place

Hi i just have a suggestion you should add these type so it would be easier to create a hitbox

export type HitboxType = "Box" | "InPart" | "Magnitude" | "Cylinder" | "TimedBox" | "TimedBall" | "WeldedBox" | "WeldedBall"

export type Opts = {
	root: BasePart | CFrame | Vector3,
	size: Vector3,
	duration: number,
	interval: number,
	OverlapParams: OverlapParams,
	debug: boolean,
	HitMode: HitMode,
	HitCooldown: number,
	IgnoreCharacters: {Model?},
	proportional : {
		scaleMultiplier: Vector3,
		offsetMultiplier: number
	}?,
	velocityPrediction: boolean,
	velocityMultiplier: number,
	dotProductFilter: {
		dotProduct: number,
		referenceVector: Vector3,
		sourcePosition: Vector3 | BasePart
	},
	blacklistParts: {BasePart}?,
	hitboxId : string | number ?,
}
function HitboxClass.new(HitboxType: HitboxType, opts: Opts)
--rest of the code 
end
1 Like

Thank you bro, you’re right!!!

2 Likes

any advice on how to increase the accuracy of the velo prediction? I’m using odm gear from attack on titan which moves extremely quickly and i need accurate attacks.

@The_NetDev I’d reccomend changing your velocity prediction code to this. It fixes an issue with the hitbox being offfset for some strange reason.

local function applyVelocityPrediction(cframe, root, velocityMultiplier)
	if not root or not root:IsA("BasePart") then
		return cframe
	end

	local velocity = root.AssemblyLinearVelocity
	if velocity.Magnitude < 1 then
		return cframe
	end

	local prediction = velocity / (velocityMultiplier or 6)

	-- convert world space velocity prediction → local space
	local localPrediction = cframe:VectorToObjectSpace(prediction)

	return cframe * CFrame.new(localPrediction)
end

@Yarik_superpro bloat-check this

2 Likes
  • It uses ipairs for some odd reason
  • It uses runtime checks :fearful:
  • It uses oop :skull:
  • It uses “signals” (man, I’m dead).
  • It does not use typecheck (harder to use).
  • bro is afraid of own code :skull_and_crossbones:
    image

3 Likes

so is this good or nah

comment comment comment

@Yarik_superpro when there’s a slight whiff of bloat and oop in the air
whiplash

2 Likes

wow so its 5.99 now sonnnnn what kind of resource is this

1 Like

Check this now.
I fixed some issues and more!

I improved this resource.
Price $4.99

You’re right. This is a good idea.
I updated the module with more features, optimized, 100% typed

the place isn’t editable anymore

1 Like