verlet integration code

local apart = game.Workspace.AnchorPart;local ppart = game.Workspace.PlanePart;local previousTime = tick(); function cloth(corner, width, height, length)		local points = {};	local constraints = {};	local m = math.sqrt(length^2 + length^2);	for y = 0, height do		for x = 0, width do			points[y] = points[y] or {};			points[y][x] = point.new((corner * CFrame.new(x, y, 0)).p);			if x ~= 0 then				local c = constraint.new(points[y][x], points[y][x-1], length);				c.line.Parent = game.Workspace.CurrentCamera;				table.insert(constraints, c);			end;			if y ~= 0 then				local c = constraint.new(points[y][x], points[y-1][x], length);				c.line.Parent = game.Workspace.CurrentCamera;				table.insert(constraints, c);				--[[				-- structure makes a difference!				if x < width then					local c = constraint.new(points[y][x], points[y-1][x+1], m);					c.line.Parent = game.Workspace.CurrentCamera;					table.insert(constraints, c);				end;				--]]			end;			if y == 0 then				points[y][x].anchored = true;			end;		end;	end;	return points, constraints;	end; local width, height, length = 10, 10, 2;local cpoints, cconstraints = cloth(apart.CFrame, width, height, length); function update()	local delta = tick() - previousTime;	previousTime = tick();	local col = collision.new(ppart);	for i = 0, height do		if i == 0 then			for i2 = 0, width do				local x = cpoints[i][i2];				x.position = (apart.CFrame * CFrame.new(i2 * length, 0, 0)).p;			end;		end;		for i2 = 0, width do			local x = cpoints[i][i2];			x:update(delta, 0.9985);			--[[			-- collision			local lide = col:pointToPlanes(x.position);			if lide then				x.position = lide;			end;			--]]		end;	end;	for i = 1, 15 do		for _, c in ipairs(cconstraints) do			c:solve();		end;	end;	for _, c in ipairs(cconstraints) do		c:draw();	end;end; game:getService("RunService").Stepped:connect(update);

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source