-- 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()
	self:applyAngle(self.neck, 0, 0)
	self:applyAngle(self.waist, 0, 0)

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

return OrientableBody
