function Damping.new()local y=setmetatable({P=5;D=.1;Position=V3(),Velocity=V3(),Goal=V3();Last=tick()},Damping)return y end function Damping.CheckNAN(y)y.Velocity=V3(CheckNAN(y.Velocity.X,0),CheckNAN(y.Velocity.Y,0),CheckNAN(y.Velocity.Z,0))y.Position=V3(CheckNAN(y.Position.X,y.Goal.X),CheckNAN(y.Position.Y,y.Goal.Y),CheckNAN(y.Position.Z,y.Goal.Z))end function Damping.Update(y)local C=tick()local e=C-y.Last y.Last=C y.Velocity=y.Velocity+y.P*((y.Goal-y.Position)+-y.Velocity*y.D)y.Position=y.Position+y.Velocity*e y:CheckNAN()return y.Position end function Damping.UpdateAngle(y)y.Goal=y.Position+DeltaAngleV3(y.Position,y.Goal)return y:Update()end
-- ================================================================================
-- PUBLIC FUNCTIONS
-- ================================================================================
function Damping.new()
	local damping = setmetatable({
		P = 5,
		D = 0.1,
		Position = V3(),
		Velocity = V3(),
		Goal = V3(),
		Last = tick(),
	}, Damping)

	return damping
end -- Damping.new()

function Damping:CheckNAN()
	self.Velocity = V3(CheckNAN(self.Velocity.X, 0), CheckNAN(self.Velocity.Y, 0), CheckNAN(self.Velocity.Z, 0))
	self.Position = V3(
		CheckNAN(self.Position.X, self.Goal.X),
		CheckNAN(self.Position.Y, self.Goal.Y),
		CheckNAN(self.Position.Z, self.Goal.Z)
	)
end -- Damping:CheckNAN()

function Damping:Update()
	local t = tick()
	local dt = (t - self.Last)
	self.Last = t
	self.Velocity = (self.Velocity + (self.P * ((self.Goal - self.Position) + (-self.Velocity * self.D))))
	self.Position = (self.Position + (self.Velocity * dt))
	self:CheckNAN()
	return self.Position
end -- Damping:Update()

function Damping:UpdateAngle()
	self.Goal = (self.Position + DeltaAngleV3(self.Position, self.Goal))
	return self:Update()
end -- Damping:UpdateAngle()
