I want to learn how to create a proper hitbox, for example one that follows a character swinging his sword. I couldn’t find anything online though about how to go about this or what method to use, so I want to know what I have to learn or use to be able to do this. I’m afraid of using a bad technique and creating a laggy hitbox, or one that’s unnecessarily taxing.
You can weld a part which has cancollide and anchored off
What technique should I use though to tell if a player has entered the hitbox?
Region3 possibly, could you elaborate on that so i can help you more.
No, dont use region3 as its deprecated. You should use spacial query instead (it’s a new version of region3) Introducing OverlapParams - New Spatial Query API
You could either make a touch connection threw client and do some verification threw server or use GetPartsInPart with a welded hitbox basepart.
Me personally I would just recommend doing any type of hit detection on client and finding a way on server to check if it counts something like distance, it helps for smoother gameplay.
My bad. I didn’t know region3 was deprecated, thank you for telling me.
what could I use for hit detection? I was trying parts in part but the issue is, I dont want to constantly run the script while a hitbox is active, i feel like that creates a lot of lag.
You could try making a Trigger function that checks if any player’s character was detected in your hitbox and if so it can return their character. It shouldn’t be a constant check unless you want to always be checking when your swinging then no you shouldn’t have performing issue doing it on client, but server would be different.
How specifically could I check if a player has entered though? What exactly could I use to check for that, if I want to check for more than an instant?
Do you mean like detecting if its a npc or player, or multiple detection in one swing ?
Also if you’re not trynna reinvent the wheel on a proper hitbox I recommend taking a look on Raycast Hitbox
Maybe this:
local swinging = false
local hadbeenattacked = {}
-- Make swinging true when you're swinging
while swinging do
for i, part in ipairs(hitbox:GetPartInParts()) do
if part.Parent:FindFirstChild('Humanoid') and not hadbeenattacked[part.Parent] then
part.Parent.Humanoid:TakeDamage(20)
table.insert(hadbeenattacked, part. Parent)
end
end
wait()
end
-- Make swinging false when you stop swinging and set hadbeenattacked back to {}
Example:
for _, v in pairs(workspace:GetPartsInPart(workspace.Hitbox) do --GetPartsInPart returns a table of parts that are touching player
if v.Name == "HumanoidRootPart" then
local char = v.Parent
--code to do smth to the character idk
end end
Here’s my hitbox guide. It sounds like you’re looking for a raycast hitbox, since you want the hitbox to precisely be where the sword is at.
As far as I know, roblox physics are genuinely awful and if you want really good hit detection, then you need to sacrifice a small amount of performance. Personally, here is what I would do
Every frame (you can use RunService.HeartBeat event) get all parts inside of the sword using workspace:GetPartsInBoundingBox(). Now that you have a list of all parts inside the sword, loop through all of them to check if it’s a valid player that you can damage
Should I do this on client side to prevent lag?
Yeah sure go ahead, but I don’t know if dealing damage on the client is a good idea…
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.