function SPRING.new(d,x,z,q,N)local f={Target=Vector3.new(),Position=Vector3.new();Velocity=Vector3.new();Mass=x or 5;Force=z or 50;Damping=q or 4,Speed=N or 4}function f.getstats(d)return d.Mass,d.Force,d.Damping,d.Speed end function f.changestats(d,x,z,q,N)d.Mass=x or d.Mass d.Force=z or d.Force d.Damping=q or d.Damping d.Speed=N or d.Speed end function f.shove(d,x)local z,q,N=x.X,x.Y,x.Z if z~=z or z==math.huge or z==-math.huge then z=0 end if q~=q or q==math.huge or q==-math.huge then q=0 end if N~=N or N==math.huge or N==-math.huge then N=0 end d.Velocity=d.Velocity+Vector3.new(z,q,N)end function f.update(d,x)local z=(x*d.Speed)/ITERATIONS for x=1,ITERATIONS,1 do local q=d.Target-d.Position local N=(q*d.Force)/d.Mass N=N-d.Velocity*d.Damping d.Velocity=d.Velocity+N*z d.Position=d.Position+d.Velocity*z end return d.Position end return f end


function SPRING.new(self, mass, force, damping, speed)

	local spring	= {
		Target		= Vector3.new();
		Position	= Vector3.new();
		Velocity	= Vector3.new();

		Mass		= mass or 5;
		Force		= force or 50;
		Damping		= damping or 4;
		Speed		= speed  or 4;
	}

	function spring.getstats(self)
		return self.Mass, self.Force, self.Damping, self.Speed
	end

	function spring.changestats(self, mass, force, damping, speed)
		self.Mass = mass or self.Mass
		self.Force = force or self.Force
		self.Damping = damping or self.Damping
		self.Speed = speed or self.Speed
	end

	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 = dt * self.Speed / ITERATIONS
		for i = 1, ITERATIONS do
			local iterationForce= self.Target - self.Position
			local acceleration	= (iterationForce * self.Force) / self.Mass

			acceleration		= acceleration - self.Velocity * self.Damping

			self.Velocity	= self.Velocity + acceleration * scaledDeltaTime
			self.Position	= self.Position + self.Velocity * scaledDeltaTime
		end

		return self.Position
	end

	return spring
end
