--	self.waistC0 = self.waist.C0;

	
	self.spring = spring.new(Vector3.new(), Vector3.new(), Vector3.new(), 10, 1);
	
	return setmetatable(self, lookAt_mt);
end

function lookAt:calcGoal(target)
	local goal = Vector3.new(0, 0, 0);
	
	local eye = (self.hrp.CFrame * CFrame.new(0, 3, 0)):pointToObjectSpace(target).unit;
	local horizontal = -math.atan2(eye.x, -eye.z);
	local vertical = math.asin(eye.y);
	
	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
	
	self.spring.target = goal;
end

function lookAt:update(dt)
	self.spring:update(dt);
	local set = self.spring.p;
	self.neck.C0 = self.neckC0 * CFrame.fromEulerAnglesYXZ(set.z*0.5, set.x, 0);