#Inaccurate hitbox detection

1 messages · Page 1 of 1 (latest)

naive girder
#

Sometimes the hit registers but at other times it doesn't. Here's the code: (server side)

function HitboxModule:Run()    
    local overlapParams = OverlapParams.new()
    overlapParams.FilterType = Enum.RaycastFilterType.Exclude
    overlapParams.FilterDescendantsInstances = ReturnPlayer(self.Owner)
        
    --self.EventConnection = UpdateHitboxes.Event:Connect(function()
    --    overlapParams.FilterDescendantsInstances = GetDescendantInstances(self.Owner)
    --end)
            
    self.RunConnection = RunService.Heartbeat:Connect(function()
        local ToolHitbox =  Utils.Validate(self.Owner, self.Weapon, true)
        if not ToolHitbox then 
            self.RunConnection:Disconnect()
            return end
        
        local part = Instance.new("Part")
        part.CFrame = ToolHitbox.CFrame
        part.Size = ToolHitbox.Size
        part.Material = Enum.Material.Neon
        part.Anchored = true
        part.CanCollide = false
        part.Parent = workspace
        
        Debris:AddItem(part, 1)
        
        local parts = workspace:GetPartsInPart(ToolHitbox, overlapParams)
        if not parts then warn("error") return end
        
        print(#parts)
                
        local characters = {}

        for _, part in parts do
            if part:HasTag("PlayerHitbox") then
                local character = part:FindFirstAncestorWhichIsA("Model")
                local humanoid = character and character:FindFirstChild("Humanoid")

                if character and (Players:GetPlayerFromCharacter(character) or character:GetAttribute("Rig")) and humanoid
                and character ~= self.Owner.Character then
                    table.insert(characters, character)
                    print(character)
                end

            else
                print("not tagged")
            end
        end

        if #characters <= 0 then return 

        elseif #characters == 1 then
            self:DamageHumanoid(characters[1], self.Damage)

        elseif #characters > 1 then
            for _, character in characters do
                self:DamageHumanoid(character, self.Damage)
            end
        end
        
        print("---------------------------------------------")
    end)
end

#

I've debugged it and found out that during the instances where the Normal rig doesn't get hit, it doesn't get registered in the parts table whatsoever either

#

I tried getpartsboundinbox but it doesn't work too

bronze furnace
#

yeah obviously

#

it relies on heartbeat

naive girder
bronze furnace
#

function HitboxModule:Run()
self.RunConnection = RunService.Heartbeat:Connect(function()
local toolHitbox = Utils.Validate(self.Owner, self.Weapon, true)
if not toolHitbox then
self.RunConnection:Disconnect()
return
end

    -- Create visual debug hitbox (optional)
    local debugPart = Instance.new("Part")
    debugPart.CFrame = toolHitbox.CFrame
    debugPart.Size = toolHitbox.Size
    debugPart.Anchored = true
    debugPart.CanCollide = false
    debugPart.Material = Enum.Material.ForceField
    debugPart.BrickColor = BrickColor.Red()
    debugPart.Transparency = 0.5
    debugPart.Parent = workspace
    Debris:AddItem(debugPart, 0.5)

    -- Setup filtering to exclude self
    local overlapParams = OverlapParams.new()
    overlapParams.FilterType = Enum.RaycastFilterType.Exclude
    overlapParams.FilterDescendantsInstances = {self.Owner.Character}

    local parts = workspace:GetPartsInPart(toolHitbox, overlapParams)
    if not parts then return end

    local hitCharacters = {}
    local processed = {}

    for _, part in ipairs(parts) do
        local character = part:FindFirstAncestorWhichIsA("Model")
        if character and not processed[character] then
            local humanoid = character:FindFirstChildOfClass("Humanoid")
            if humanoid and character ~= self.Owner.Character then
                local player = Players:GetPlayerFromCharacter(character)
                if player or character:GetAttribute("Rig") then
                    table.insert(hitCharacters, character)
                    processed[character] = true
                end
            end
        end
    end

    -- Apply damage
    for _, character in ipairs(hitCharacters) do
        self:DamageHumanoid(character, self.Damage)
    end
end)

end

naive girder
#

I've tried Stepped too

bronze furnace
#

try that script instead

naive girder
#

I'm using collection service to handle hitboxes I'm pretty sure that's more optimized than just blatantly checking for part ancestry no?

bronze furnace
#

local CollectionService = game:GetService("CollectionService")

function HitboxModule:Run()
self.RunConnection = RunService.Heartbeat:Connect(function()
local toolHitbox = Utils.Validate(self.Owner, self.Weapon, true)
if not toolHitbox then
self.RunConnection:Disconnect()
return
end

    -- Get all tagged hitbox parts
    local candidateParts = CollectionService:GetTagged("PlayerHitbox")
    local hitCharacters = {}
    local processed = {}

    for _, part in ipairs(candidateParts) do
        if part:IsDescendantOf(workspace) and toolHitbox:IsA("BasePart") and part:IsA("BasePart") then
            if part:IsDescendantOf(self.Owner.Character) then
                continue -- Skip own character
            end

            -- AABB check or .Magnitude for proximity (customize as needed)
            local dist = (toolHitbox.Position - part.Position).Magnitude
            if dist <= (toolHitbox.Size.Magnitude / 2 + part.Size.Magnitude / 2) then
                local character = part:FindFirstAncestorWhichIsA("Model")
                local humanoid = character and character:FindFirstChildOfClass("Humanoid")
                if humanoid and not processed[character] then
                    table.insert(hitCharacters, character)
                    processed[character] = true
                end
            end
        end
    end

    -- Damage all valid characters
    for _, character in ipairs(hitCharacters) do
        self:DamageHumanoid(character, self.Damage)
    end
end)

end

#

heres with collection service

#

you should probably be using raycasts

#

you are relying on heartbeat which could miss fast events, even with collection service this isnt optimal

#

and the current method isnt inaccurate, its just unreliable :p

naive girder
#

still doesn't work

naive girder
#

it doesn't work either

naive girder
bronze furnace
#

bro stepped is bad too

naive girder
#

what should I use then

bronze furnace
#

just raycast

#

i mean tbh you shouldnt be running into any issue of hitboxes. you should be relying on magnitude with spatial partitioning mainly

#

im still trying to figure out why this is necessary for your system. you should be able to optimize by spatial partitioning, deduce magnitude between objects and then perform raycasts to detect interactions

naive girder
#

I'll look into it

patent walrus
#

does the script works?

sacred topazBOT
#

studio** You are now Level 4! **studio