Hitbox or Touched event for detection?


So I’ve basically already made the pathfinding thing, it works fine and all. But my question is if I am killing the NPC the best way I can? I am putting it in my while true do loop which yields to a runservice.Heartbeat:Wait(). The way I am detecting a player is by using workspace:GetPartsInBox.
I had three methods of detection:

  • Hitbox (Good Detection, Less optimal)
  • Touched Event (Optimal)
  • Checking distance is below a certain range and then killing the player (Good detection, less optimal. players annoyed they can’t move around the NPC)

I avoided the last one because I thought it would be very annoying if you are in a room and you wouldn’t be able to walk around the NPC or something. But it was an option I considered, but I was between the touched event and hitbox. I chose the hitbox for detection purposes, but was this the best idea? By the way the box is basically the size of the block rig.

local params = OverlapParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {workspace.Rig}
	local hitbox = workspace:GetPartBoundsInBox(rigtorso.CFrame, workspace.Box.Size, params)
	for i, part in hitbox do
		if part.Parent:FindFirstChildOfClass("Humanoid") then
		part.Parent:FindFirstChildOfClass("Humanoid").Health = 0
		end
	end

Also if you guys could please let me know if you think this is a good NPC, I don’t think it lagged either in the video but I was thinking that it might do in the real game when there’s more players and not in a studio server. Or am I wrong? Did I make the right choice?

  • Hitbox (My choice)
  • Touched

0 voters

Unless you need something super precise or have high velocity projectiles I’d stay .Touched() is good enough. No need to reinvent the wheel.

2 Likes

But I’m pretty sure .Touched can be inconsistent right? If it was a big game then it might be an issue no?

You should try out ZonePlus

If you’re going to be siding with a hitbox method, it is very popular and optimised and I use it myself from time to time.

The reason I am recommending you to use this is because GetPartBoundsInBox is quite heavy on performance, so if this would be affecting your game in any amount, please use ZonePlus

1 Like

Yeah I just switched to .Touched in the end.

Ah alright, good luck on your game!

Thank you. Good luck to you too if you are doing anything.

.Touched is unreliable if you’re moving parts by directly setting their CFrames.

please do not ever use .touched event for detection it is incredibly inconsistent especially when the part is moving. you’re better off using raycasthitboxv4 or zoneplus instead

1 Like

It’s just to check if a player touched the NPC. Plus the poll also shows what the majority think is better.

it’s your choice to go with .Touched but if i were you i would stick to stuff like raycasting, region3, magnitude, zone or raycasthitboxv4. they provide a more reliable and consistent hitbox

The problem with a hitbox is that it would feel like you got killed when you weren’t even close, with .Touched you can go around the NPC alot more. I’ve tested both methods, same with magnitude, I did use raycasting to detect obstacles in the way of the NPC that it could jump over though. Also, I’m pretty sure region3 is deprecated.

region3 is deprecated but functions better than .Touched. the only problem with .Touched is that especially when the target is moving it is inconsistent. use what you wanna use

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