NPC hit detection rarely hits BlockHitbox

I want to make the npc not damage the player when player is blocking with their sword, and get parried if parry value inside the player was true, the grey block is BlockHitbox.

Issue is that it rarely hits the BlockHitbox and damages player, usually hits head or arm instead of the BlockHitbox.

Should i make the BlockHitbox bigger? is there something wrong with my hit detection?

			local hitCache = {}
			local par = false
			local hit = false
			
			local raycastParams = RaycastParams.new()
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			raycastParams.FilterDescendantsInstances = {model}
			local hitbox = ShapecastHitbox.new(blade, raycastParams)

			task.spawn(function()
				task.spawn(function()
					task.wait(settings.BeforeSlashSound)
					Utils.playSlashSound(settings, model)
				end)
				
				
				task.wait(settings.TimeToParry[state.combo])
				blade.CanTouch = true
				hitbox:HitStart(3):OnUpdate(function()
					if hitbox.RaycastResult then 
						local part = hitbox.RaycastResult.Instance
							
							local char = part:FindFirstAncestorOfClass("Model")
							if not char or not char:FindFirstChild("Humanoid") then return end
							if hitCache[char] or (not state.attacking and not state.stunned) then return end
							hitCache[char] = true
							
							print(part.Name)
							
							local targetHumanoid = char:FindFirstChild("Humanoid")
							
							local blee = true
							if helper then
								if char ~= owner.Character then
									blee = false
								end
							end
							if part.Name == "BlockHitbox" and not par and not hit and blee then
								if char:FindFirstChild("Parry").Value == true then
									local p = Combat.Parried(state, model, blade, target, root, state.hitConnection, humanoid, etype, track)
									par = true
								else
									Combat.Blocked(model, blade, root)
								end
							else
								if not par and not hit then
									local isHelperHittingPLayer = true
									if not char:FindFirstChild("Evil") and helper then
										isHelperHittingPLayer = false
									end
									if isHelperHittingPLayer then
										local h = Combat.Damage(etype, targetHumanoid, char, part, settings)
										if h then hit = true end
									end
								end
							end
					
					end
				end)
			end)
			
			ShapecastHitbox.Settings.Debug_Visible = true
			track.Stopped:Connect(function()
				state.combo = (state.combo % #settings.animations) + 1
				hitbox:HitStop():Destroy()
				state.attacking = false
				model.Attacking.Value = false
			end)

			continue
		end

Any help is appreciated

Hmmm i think it because your hitbox block is small and u use raycast hitbox i think raycast should do a range weapon hitbox but normaly i never see a hitbox block like this one i think u should use a magnitue in instance hitbiox block check the player or target is on your back or na

I usually just use a dot product for checking whether the enemy is behind the player or not. It’s always been reliable.

its like this so they dont get parried when the attack already went through the player, im trying to get ahead of the small delay.

Sorry i dont really know what you’re saying in some parts, im using raycast hitbox because Touched event fails easily, could you elaborate what you mean in the rest of the reply?

I advise using a hitbox system like elden rings instead of touched because its inconsistent one it uses cylinder capsules as the hitbox around a weapon and players body(its kind of there already though) that uses get’s parts in bound box with overlaps params. I personally find the roblox.touch to be a bit more inconsistent or you could just do raycast’s also probably prioritize the box before the character because you might be hitting the character first then the box

I am using raycast hitboxes, not touched, so instead i should try checking parts in bound box in heartbeat?

I used simple solution to just use it as extended hitbox for blocking instead of being the only one, so now both player and blockhitbox block, and as ExecuteAsk_Allow mentioned im just gonna use dot to check angle.

Sorry I did not read the script fully but I actually think that the raycasting is fine the main problem is that it is reading the players body first then the box so you need to fix the block/parry check.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.