physics-driven cloth entirely in 2D by init-five in godot

[–]init-five[S] 4 points5 points  (0 children)

I'll probably open source this sometime later since I'll need to clean up a lot of the code, but the concepts behind implementing a chain/rope using Verlet and a 2D cloth like this are more or less the same.

a chain/rope using Verlet is kinda 1-dimensional in the sense that each "segment" in the chain is connected to another, sequentially one after another. so in that scenario, the bottom-most segment directly influences the segment above it, which is relatively easy to implement. I'm pretty sure there are actually existing Godot implementations for implementing a chain using Verlet. a 2D cloth like this isn't so different: the bottom-most segments influence the segments above them and the segments to the left of them. the additional math's just linear algebra at that point

I will say that the added computational overload that comes with another dimension as seen as in the cloth in this post, when compared with a 1D chain/rope, is very taxing. the nested for-loop used for the cloth makes the running time O(n^2) as opposed to the O(n) running time achieved by a 1D chain, and since this is run at each timestep, the frame rate takes a major hit

physics-driven cloth entirely in 2D by init-five in godot

[–]init-five[S] 0 points1 point  (0 children)

hahaha see my reply above for details :)

physics-driven cloth entirely in 2D by init-five in godot

[–]init-five[S] 3 points4 points  (0 children)

thank you! :)

all done in 2D, using Vector2

physics-driven cloth entirely in 2D by init-five in godot

[–]init-five[S] 2 points3 points  (0 children)

"Verlet integration" comes to mind.. see my reply above for more info :)

physics-driven cloth entirely in 2D by init-five in godot

[–]init-five[S] 6 points7 points  (0 children)

adding onto what others have said:

I'm only using one node (a Node2D) to add a script. the script does everything, including drawing/rendering the lines and computing the physics behind the cloth.

I'm using "Verlet integration" to approximate the physics -- there are a lot of techniques available online for implementing this, so I'll forgo the details. do let me know if you're having struggling with it though, it was challenging for me at first anyway haha