lua verlet integration
snippet in lua

lua verlet integration

user749

self.canBreak
self.restDist, self.breakDist

local sep = (p1 - p2)
local fac = (self.restDist - sep.magnitude) / sep.magnitude

local restore = sep * 0.5 * fac
point1.pos = not point1.inert and point1.pos + restore
point2.pos = not point2.inert point2.pos - restore

if self.canBreak and sep.magnitude > self.breakDist then
	self:tear()
end