How Would I Make A Good Raycast Hitbox For Barrage Ability?

So I’ve been working on a couple of combat abilities for my game and I got stuck on making a barrage ability(Fast punches with arms going in front of character as an effect). I’ve been always using simple hitboxes for abilities with Hitbox.Touched event, but this method is pretty bad for making barrage abilities, the script creates a bunch of hitboxes that touch each other instead of touching the enemy, so the punches are really rare. I don’t want to use the rotated Region3 method, because it’s similar to hitbox and will cause the same issue, so I’m asking you, guys, how to make a raycast hitbox for my barrage ability. If you’re still confused, I mean I want to make a raycast from somewhere of the character, most likely from the “Going arms in front of my character effect”, and when the ray hits the target, the enemy takes damage. The Hitbox and effects can be separate. I have a code example, but it doesn’t work like I wanted it to, rays hit the enemy rarely:

while Barraging do
		local pivotCFrame = char.HumanoidRootPart.CFrame * CFrame.new(0,0,-6)
		
		local LArm = char["Left Arm"]:Clone()
		LArm:ClearAllChildren()
		LArm.CanCollide = false
		LArm.Anchored = true
		LArm.Parent = Folder
		Debris:AddItem(LArm,.25)
		local RArm = char["Right Arm"]:Clone()
		RArm:ClearAllChildren()
		RArm.CanCollide = false
		RArm.Anchored = true
		RArm.Parent = Folder
		Debris:AddItem(RArm,.25)
		
		LArm.CFrame = CFrame.new((char.HumanoidRootPart.CFrame * CFrame.new(math.random(-2,-1.5),0,-1)).p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
		RArm.CFrame = CFrame.new((char.HumanoidRootPart.CFrame * CFrame.new(math.random(1.5,2),0,-1)).p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
		
		local Tween1 = TS:Create(LArm,TweenInfo.new(.25),{Transparency = 1, CFrame = LArm.CFrame * CFrame.new(0,-3,0)}):Play()
		local Tween2 = TS:Create(RArm,TweenInfo.new(.25),{Transparency = 1, CFrame = RArm.CFrame * CFrame.new(0,-3,0)}):Play()
		
		local rayParams = RaycastParams.new()
		rayParams.FilterDescendantsInstances = {char}
		rayParams.FilterType = Enum.RaycastFilterType.Blacklist

		local L_Start = LArm.CFrame * CFrame.new(0,LArm.Size.Y/2,0)
		local R_Start = RArm.CFrame * CFrame.new(0,RArm.Size.Y/2,0)

		local rayL = workspace:Raycast(L_Start.p, CFrame.new(L_Start.p, LArm.CFrame.p).lookVector * 6, rayParams)
		local rayR = workspace:Raycast(R_Start.p, CFrame.new(R_Start.p, RArm.CFrame.p).lookVector * 6, rayParams)
		
		if rayL then
			local eHum = rayL.Instance.Parent:FindFirstChild("Humanoid")
			if eHum then
				print(eHum.Parent)
			end
		end
		
		if rayR then
			local eHum = rayR.Instance.Parent:FindFirstChild("Humanoid")
			if eHum then
				print(eHum.Parent)
			end
		end
		wait(.05)
	end

Any help is greatly appreciated. Thanks in advance.

This open-sourced module might be what you needed:

I looked through the tutorial and it’s a great module indeed. But I don’t see any good way I can adapt it to my barrage ability, since every new punch is created every like 0.05 or 0.1 seconds, the hitbox hits only once, and It seems to me I can’t just HitStop() every time the loop is ended, the second issue is that where should I create the hit attachments for this raycast hitbox?

You could use BasePart:GetTouchingParts() instead of Touched, like this:

-- local hitbox function (super simplified)
for i = 1, 10, 1 do --Ten hitboxes/punches
    local Hitbox = OriginalHitbox:Clone()
    Hitbox.CFrame = CharRoot.CFrame:ToWorldSpace(Offset)
    local Taglist = {PlayerCharacter} --each hitbox only hits once per character

    for _, v in ipairs(Hitbox:GetTouchingParts()) do
        if not table.find(Taglist,v.Parent) and v.Parent:FindFirstChild("Humanoid") then
            Taglist[#Taglist+1] = v.Parent
            DamageHumanoid:FireServer()
        end
    end

    delay(0.1,function()
        Hitbox:Destroy()
    end)

    wait(0.1)
end

I use something like this for the game i’m developing and so far it works pretty fine, i think this would work well with the barrage you want to do.

Thank you for the response. It seems like the Hitbox:GetTouchingParts() function doesn’t work at all.The Hitbox.Touched worked fine, but this function doesn’t work for some reason, it doesn’t even get the v value. And I still would like to make a raycasting hitbox system, if you have any ideas, let me know.

I just noticed that GetTouchingParts got replaced… OverlapParams
Try using the GetPartsInPart, maybe it will work better than GetTouchingParts

Same goes with these two function, looks like hitbox.Touched is the only working one.
Edit. I figured it out, the CanCollide must be set to true. And this function is working, however, since the can collide is set true, you can barrage into the air, then rotate towards the enemy, that stands next to you, and they will me moved by the hitbox, which is weird and unwanted. I still need a raycast hitbox.

This is a bit late but you might wanna use region3 for hitboxes, ill be more than happy to explain to you how region3 hitboxes can work

2 Likes

Alright. I’ve been using the :GetTouchingParts() function, but I’ve seen many people using region3 for barrages. Your help will be highly appreciated!

Sorry for late ping but a explanation would be nice