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 :
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?
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.
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
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.
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.
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.
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.
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)