Tired of using Touched for weapon hitboxes? Use HitboxCaster

Introduction :

Ah yes the famous BasePart.Touched, why in the world would I make a module to replace Roblox’s built-in feature? Touched’s reliance on physics is what causes performance problems and makes it vulnerable to network ownership exploits when called on the server, etc

Well I’ve made a short module that replaces Touched for weapon hitboxes such as swords.

Why raycast :

Well basically raycasting has always been the best method for hitboxes due to the little amount of resources it uses. Region3 uses more resources since it is a 3D hitbox and takes more math, with the new raycasting method, raycasting uses little to no resources(probably an exaggeration).

Example :

Here’s a clip of my hitbox module working in my MMORPG game in dev, Resurgence :

https://gyazo.com/99895ed296f84cb7c508d9d136a9de30 ← You can’t clearly see the 3rd hit’s missing indicator and can clearing see the last hit not touching the target at all. I’m a bad UI designer XD.

This is how the hitbox looks like : https://gyazo.com/69d73ecb2ff8812250d6ac35b645149c

Code :

Here is the module and API for HitboxCaster, lol yes I stole DmgPoint from the Raycast Hitbox guy lol and here’s an example code for it.

Updated the example code alongside the module

local HitboxCaster = require(PathToHitboxCaster)
local Hitbox = HitboxCaster(WeaponHandle)

Hitbox.Signal:Connect(function(Part, Model, Hum)

end)

Hitbox:Cast{workspace.Baseplate}

wait(.5) -- lol wait

Hitbox:Stop()
38 Likes

Could you explain why we should use this over RaycastHitbox and what are the advantages/disadvantages to your module? As well as what this has that the other one doesn’t.

And could you explain where the model and humanoid parameters come from?

2 Likes

The parameters aren’t random look in the module yourself(updated the API to add the parameters for Hitbox:Cast()). I’ve never compared mine with raycast hitbox. But ok in terms of lines of code, mine is way way shorter by 5x times. Raycast Hitbox just seems like a mess in terms of organization(no dissing). Look at the amount of unnecessary functions, mine has very few functions comparing to it.

Popular scripts are popular for a reason - either for ease of use, or how efficient they are.
I’d expect that a script that has been released to the public and used by it for a prolonged period of time would be polished, for maximum efficiency.

Instead of assuming you could try taking a look at the code yourself.

1 Like

when i do hitboxes i always implement my own custom angle system and rely on magnitude. RaycastHitbox requires precise hits on the attachments to register a hit, and if you’ve got more than 1 person in front of you only one will be damaged. you should use a combination of angle calculating and distance calculating and do a loop through all characters. for the characters, in order to maximize performance you should use CollectionService to keep track of all current characters

1 Like

Also just made a performance comparison, here are the results.

Raycast Hitbox : https://gyazo.com/53a2333cf5ab29e9024e9b81d6127836
Mine : https://gyazo.com/cc9f3e88786a38ceb5e16abb2f7b0405

1 Like

Thanks for the feedback. I’ll make sure it becomes better.

1 Like

comparison.rbxl (42.0 KB)
Here is the place for the comparison.

1 Like

Not gonna lie, very factual of you lol and I didn’t criticize the owner.

1 Like

I did some research and asked consultation from my friends and it seems like what I’m doing is good enough. Mine is precise enough, it runs every frame so its supposed to be somewhat accurate and im also I’m just subtracting the previous position from the current and raycast from those 2 points. I may consider implement CollectionService if possible tho.

Here’s my thing hitting multiple targets.
https://gyazo.com/66f47d13363dd48d6b1ef84a8d8ccf9e

If you want to be able to hit one target then, it’s pretty easy.

local NewHitbox = Module(WeaponHandle)

NewHitbox:Cast{Character} -- Starts casting
local Part, Model, Humanoid, WeaponHandle = NewHitbox.Signal:Yield() -- It's RBXScriptSignal:Wait()'s equivalent of my Signal module.

Your method is completely fine and this is a nice module you’ve got here, I’m just sharing a personal preference

Oh ok well you do you then ig :slight_smile:

I’ve updated the module once again bc there was a bug where u could hit the same character twice within the same Cast bc it only blacklisted the touched parts and not the whole character

How is this more efficient than using touch events? It seems to be the opposite to me. I’d feel comfortable hooking up 100+ touch events to spinning death obstacles, but I would not feel comfortable doing the same with this raycasting hitbox module.

Also, could you explain more about network ownership exploits and how this can be used to combat this problem?

yo idk about that lol
scripts & modules can be popular just because a big name is behind them, e.g egomoose & clonetrooper
it isn’t a given that they’re perfectly efficient.

Also the typical over engineering; useless methods, pointless inclusion of other modules, and making much more than necessary that is found in the typical community resource post, i’d say it’s safe to say that scripts aren’t efficient because they’re popular, shouldn’t even have to say that lol.

6 Likes

Also, could you explain more about network ownership exploits and how this can be used to combat this problem?

Learn how network ownership works(a part would have its network ownership automatically set to the closest player within a certain radius assuming the network owner hasn’t been set yet via code or the part isn’t anchored). If you have network ownership of a part, any changes applied to it on ur client would replicate to the server, hence the name network owner.

Touched : https://gyazo.com/cb122f9224bf9195d6ed02314f05f9f0

Ok Touched only reacts to physics, and look at the script activity. It’s worse than Raycast Hitbox in a heartbeat connection

Raycast Hitbox : https://gyazo.com/53a2333cf5ab29e9024e9b81d6127836

No I made a Touched Connection once and it was worse than doing this in terms of script activity by a lot

local Hitbox = require(RaycastHitbox):Initialize(Part, {Part}) -- Comparing with Raycast Hitbox, since mine is already significantly better than Raycast Hitbox(shown in the comparison earlier).

Hitbox.OnHit:Connect(function()
    -- Takedamage
end)

Heartbeat:Connect(function()
    Hitbox:HitStop()
    Hitbox:HitStart()
end)

That’s why I deleted my post, I realized I misunderstood what you were saying.

Oh ok, well now you get it :slight_smile:.