-- Functions 


function SPRING.create(mass, force, damping, speed)
	local spring	= {
		Target		= Vector3.new();
		Position	= Vector3.new();
		Velocity	= Vector3.new();
		Time 		= 0;

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

	return setmetatable(spring, Meta)
end

function SPRING:shove(force)
	local x, y, z	= force.X, force.Y, force.Z
	if x == math.huge or x == -math.huge then
		x	= 0
	end
	if y == math.huge or y == -math.huge then
		y	= 0
	end
	if z == math.huge or z == -math.huge then
		z	= 0
	end
	self.Velocity	+= Vector3.new(x, y, z)
end

function SPRING:update(dt)
	local Time = math.min(self.Time + dt * self.Speed, FixedRate * MaxSkips)
	
	for i = 1, math.floor(Time / FixedRate) * ITERATIONS do
		local iterationForce = self.Target - self.Position
		local acceleration	 = (iterationForce * self.Force) / self.Mass

		acceleration	-= self.Velocity * self.Damping

		self.Velocity	+= acceleration * iterdt
		self.Position	+= self.Velocity * iterdt
		Time -= iterdt
	end
	
	self.Time = Time
	if self.Position.Magnitude > .00001 then
		return self.Position
	end
	return Vector3.zero
end
