I was interested in finding out if the cloth like dynamics demonstrated would be possible in Unity. I was thinking that it might be possible using a script connected to a model, and the mesh deforming to make the ‘cloth’ deform when it came in contact with other things, but that would be really processor intensive!
Anyone tried this or have any idea how this could be done?
I’ve tried this once - a script that calculates cloth dynamics and it’s collisions with several spheres and generates mesh accordingly. Yes, it is CPU intensive, but it works.
Generally, cloth simulation is a small detail in a game: a character’s clothes, or a banner hanging up, something like that; given that, it’s probably not worth it in situations like that until a more efficient cloth algorithm pops up.
Aras: you said it generated a mesh dynamically; I’d think that’s not the most efficient way to do it. What I was thinking was a mesh with bones, and spring joints between the colliders, set up basically the same way as a ragdoll. Would that work? Wouldn’t it be more efficient than generating a mesh every frame?
Yes, a skinned mesh would also work. Would be harder to simulate cloth folding (because you’d need lots of bones), but for curtains and such could be perfect.
On a related note, I decided to give this a shot, but I’m having trouble adding the joints: I can’t add more than one spring joint to each rigidbody. Any suggestions?
interesting article- but it points out one clear question
Is the interest more in modeling cloth physical interactions, or cloth looking objects? I think rendering an object that looks and behaves like cloth might be possible already, if you want cape and curtain behavior- maybe even a cloth shader?
I for one would love to use fake cloth shading- actual cloth physics would be AMAZING but I can’t see that being very performance useful with my current understanding of the computations involved.
I’ve tried that script, it works pretty well, the author even has some examples in his website. All I’ve done with it is a jello looking cube that bounces and deforms, but I saw a flag example in the website.
Hey guys, I’m trying to create cloth using a spring mass system made entierly out of unity components, basically I create a mesh made out XbyY vertices that get updated each frame based on the position of rigid bodies connected by springs.
Each mass is a rigid body with children containing the spring connections, to all adjacent masses, horizontally, vertically and diagonally, so each mass contains a max of 8 children each with a spring and a fixed joint that connects the children to its parent (the mass), I did it this way to bypass the limitation of 1 spring per GameObject.
My cloth looks ok, but when I add colliders to the masses all hell breaks lose.
Here’s an exaple web player so you can see side by side what I mean.
Both cloth objects were created by the same script, I added sphere colliders to the one in the left, the colliders are very small and are not touching, I even added code to ignore collisions between them.
no, I generate the mesh using an editor wizard, the result is just a mesh filter and a mesh renderer with all the masses as children, could it be that Unity is creating a compound collider because my masses with colliders are all children of the cloth and that is screwing things up?
The mesh doesn’t actually move anywhere, the vertices do, so the only parents that are moving around are the masses which have the objects with springs as children. Even if it was an issue of moving the parent why would the cloth in the right behave correctly?