-- Use the character attribute (updated by the server) as the source of truth for body orientation
-- Intended to be used for replicated characters

function OrientableBody:useAttributeAsSource()
	self:orientFromAttribute()
	self.attributeConnection = self.character:GetAttributeChangedSignal(ATTRIBUTE):Connect(function()
		self:orientFromAttribute()
	end)
end

function OrientableBody:destroy()
	if self.attributeConnection then
		self.attributeConnection:Disconnect()
		self.attributeConnection = nil
	end
	if self.renderStepConnection then
		self.renderStepConnection:Disconnect()
		self.renderStepConnection = nil
	end

	self.motor:setGoal({
		horizontalAngle = Otter.spring(0),
		verticalAngle = Otter.spring(0),
	})

	self.motor:onComplete(function()
		if self.motor then
			self.motor:destroy()
			self.motor = nil
		end
	end)
end

return OrientableBody
