function Damping.new()local l=setmetatable({P=5;D=.1;Position=V3(),Velocity=V3();Goal=V3(),Last=tick()},Damping)return l end function Damping.CheckNAN(l)l.Velocity=V3(CheckNAN(l.Velocity.X,0),CheckNAN(l.Velocity.Y,0),CheckNAN(l.Velocity.Z,0))l.Position=V3(CheckNAN(l.Position.X,l.Goal.X),CheckNAN(l.Position.Y,l.Goal.Y),CheckNAN(l.Position.Z,l.Goal.Z))end function Damping.Update(l)local i=tick()local x=i-l.Last l.Last=i l.Velocity=l.Velocity+l.P*((l.Goal-l.Position)+-l.Velocity*l.D)l.Position=l.Position+l.Velocity*x l:CheckNAN()return l.Position end function Damping.UpdateAngle(l)l.Goal=l.Position+DeltaAngleV3(l.Position,l.Goal)return l:Update()end

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()