Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make better hitboxes?

Asked by
neoG457 315 Moderation Voter
8 years ago

Im trying to inflict damage on a dummy with a punching script I made. In this script I used a part that appears and disappears each time the mouse is clicked, it inflicts damage but not all the time. This is the only hitbox method I know so please help me.

This is what it looks like: Punches

The grey part is my hit box and the dummy should take damage each time it touches it.

And this is a part of the script I'm using:

local debounce = false

local   Box = Instance.new("Part")

local   boxweld = Instance.new('Weld')
        boxweld.Name = "CWelds"
        boxweld.Part0 = Player.Character.Torso
        boxweld.Part1 = Box
        boxweld.Parent = Player.Character.Torso
        boxweld.C0 = CFrame.new(0, -1, -2)*CFrame.Angles(0, 0, 0)

        Box.Size = Vector3.new(4, 5, 4)
        Box.CanCollide = false
        Box.Anchored = false
        Box.Transparency = 0.5
        Box.Name = "Box"
        Box.Parent = Player.Character

Box.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    if h and (not debounce) and (h.Parent ~= Player.Character) then
       debounce = true
         h:TakeDamage(math.random(10, 14)) 
        Box:Destroy()

end
end)

This isnt all of the script however it is where the problem is, if you need the whole script please tell me.

1 answer

Log in to vote
2
Answered by 8 years ago

Raycasting

Have you considered instead checking if the Player is facing the target and if they can hit the target?
A lot of games out there use this method instead of checking the mesh because putting a hitbox on the weapon and checking for an intersection can be inconvenient in certain games where this checking is not reliable or necessary (More overhead than raycasting, provided their masking is right).

Send a ray from the torso, in the direction of the torso, for about 2.5 studs, check if it hits a character and then damage the character it hit. Make sure you set the mask to ignore the Player's character.

0
Thanks, I'll leave this open for a little bit longer to see if there are any other suggestions but if not I'll accept your answer. neoG457 315 — 8y
0
The alternative is to simply check if the arm collides with the player using Touched. I wouldn't trust it for this case, and I'd rely on a raycast if I were you. Even more important to rely on a raycast if you're using networked combat, which you are. User#6546 35 — 8y
Ad

Answer this question