function spring.update(J,D)local I=J.position-J.target local f=-J.stiffness*I local z=-J.damping*J.velocity local T=f+z local g=J.velocity+T*D local y=J.position+g if absDist(g)<J.precision and absDist(J.target-y)<J.precision then J.position=J.target J.velocity=J.velocity-J.velocity return end J.position=y J.velocity=g end


function spring:update(dt)
	local displacement = self.position - self.target;
	local springForce = -self.stiffness * displacement;
	local dampForce = -self.damping * self.velocity;
	
	local acceleration = springForce + dampForce;
	local newVelocity = self.velocity + acceleration*dt;
	local newPosition = self.position + newVelocity;
	
	if (absDist(newVelocity) < self.precision and absDist(self.target - newPosition) < self.precision) then
		self.position = self.target;
		self.velocity = self.velocity - self.velocity;
		return;
	end
	
	self.position = newPosition;
	self.velocity = newVelocity;
end
