function SPRING.Create(q,y,K,b,d)local c={Target=Vector3.new();Position=Vector3.new();Velocity=Vector3.new(),Mass=y or 1,Force=K or 50;Damping=b or 2;Speed=d or 1}function c.Shove(q,y)local K,b,d=y.X,y.Y,y.Z if K~=K or K==math.huge or K==-math.huge then K=0 end if b~=b or b==math.huge or b==-math.huge then b=0 end if d~=d or d==math.huge or d==-math.huge then d=0 end q.Velocity=q.Velocity+Vector3.new(K,b,d)end function c.Update(q,y)local K=math.min(y*q.Speed,.1)local b=q.Target-q.Position local d=(b*q.Force)/q.Mass d=d-q.Velocity*q.Damping q.Velocity=q.Velocity+d*K q.Position=q.Position+q.Velocity*K return q.Position end return c end


function SPRING.Create(self, mass, force, damping, speed)
	local spring	= {
		Target		= Vector3.new();
		Position	= Vector3.new();
		Velocity	= Vector3.new();
		
		Mass		= mass or 1;
		Force		= force or 50;
		Damping		= damping or 2;
		Speed		= speed or 1;
	}
	
	function spring.Shove(self, force)
		local x, y, z	= force.X, force.Y, force.Z
		if x ~= x or x == math.huge or x == -math.huge then
			x	= 0
		end
		if y ~= y or y == math.huge or y == -math.huge then
			y	= 0
		end
		if z ~= z or z == math.huge or z == -math.huge then
			z	= 0
		end
		self.Velocity	= self.Velocity + Vector3.new(x, y, z)
	end
	
	function spring.Update(self, dt)
		local scaledDeltaTime	= math.min(dt * self.Speed, 0.1)
		
		local force			= self.Target - self.Position
		local acceleration	= (force * self.Force) / self.Mass
		
		acceleration		= acceleration - self.Velocity * self.Damping
		
		self.Velocity	= self.Velocity + acceleration * scaledDeltaTime
		self.Position	= self.Position + self.Velocity * scaledDeltaTime
		
		return self.Position
	end
	
	return spring
end
