local function e(e)local C=((hrp.CFrame*CFrame.new(0,3,0)):pointToObjectSpace(e)).unit local N=-math.atan2(C.x,-C.z)local L=math.asin(C.y)local H=Vector3.new()if not(math.abs(N)>settings.horizontalRange or math.abs(L)>settings.verticalRange)then local e,C=math.sign(N),math.abs(N)local r,g=C*.5,C*.5 if g>settings.maxHorizontalWaist then local e=g-settings.maxHorizontalWaist g=settings.maxHorizontalWaist r=math.clamp(r+e,0,settings.maxHorizontalHead)end H=Vector3.new(e*r,e*g,L)end return H end
-- returns the angles needed to have the npc look at a target

local function lookAt(target)
	local eye = (hrp.CFrame * CFrame.new(0, 3, 0)):pointToObjectSpace(target).unit
	local horizontal = -math.atan2(eye.x, -eye.z)
	local vertical = math.asin(eye.y)

	local goal = Vector3.new()
	if not (math.abs(horizontal) > settings.horizontalRange or math.abs(vertical) > settings.verticalRange) then
		local hsign, habs = math.sign(horizontal), math.abs(horizontal)
		local hneck, hwaist = habs * 0.5, habs * 0.5

		if hwaist > settings.maxHorizontalWaist then
			local remainder = hwaist - settings.maxHorizontalWaist
			hwaist = settings.maxHorizontalWaist
			hneck = math.clamp(hneck + remainder, 0, settings.maxHorizontalHead)
		end

		goal = Vector3.new(hsign * hneck, hsign * hwaist, vertical)
	end

	return goal
end
