Modular hit detection system aint workin

hi my hit detection stuff hitting things outside of the range i give it
it seems like the angle is a lot bigger than it is supposed to be
i dont really understand dot or unit or any of that as i havent looked into it much and stole that part from some other devforum post but i can clearly see it aint workin

function HitDetection(enemy, range, degrees)
	local hits = {}

	for iterator, tower in pairs(collectionservice:GetTagged("hit")) do
		local lookVector = enemy.HumanoidRootPart.CFrame.LookVector
		local Vector = (tower.Position - enemy.HumanoidRootPart.Position)
		local normalized = Vector.Unit
		local dist = Vector.Magnitude

		local dot = lookVector:Dot(normalized)
		local angle = math.deg(math.acos(dot))

		if dist <= range and angle <= degrees then
			table.insert(hits, tower)
			local h = Instance.new("Highlight") 
			h.FillColor = Color3.new(0.403922, 0.921569, 1)
			h.Parent = tower
		end
	end

	if hits[1] then
		return hits
	else
		return
	end
end

HitDetection(workspace.me, 30, 35)

here is what is happening
blue highlighted parts are what the server is hitting
everything within the red or green is what is supposed to be hit

ok bye

im an idiot forgot to divide degrees by 2

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