I’m making a soccer net in Unity 5 using the Cloth component. I would like the net to behave as if it were made of spandex (really stretchy) to achieve an exaggerated look. I have the basic system working, but I can’t seem to get the cloth to stretch very far. Is there some setting I can mess with to adjust the stretchiness of the cloth? I’m using a standard capsule collider for my ball, if that helps.
My goal is something like this:
My current system gets to about a fourth of that. Maybe not even.
Any help is greatly appreciated. Thank you in advance.
It’s actually quite possible to produce the effect of the net with the current cloth system (in Unity 5).
The main issue you will face isn’t related to the cloth itself, but more toward the interacting physics related to the contact between the ball and the net.
There’s also the level of skills and knowledge you can have access to at the moment.
The easiest method is as follow :
First, by using the current cloth component, you will have make the net as a flat double sided mesh with opacity. This means you will have to modify a bit of the shader if you wish to use the standard shader. This explain it a bit : Unity - Manual: ShaderLab: commands
The amount of polygons in the net should be the equivalent to a quarter the size of the polygon on the ball. So, depending on the size of the polygon on your ball, the net surface will include 4x more polygons. Normally, you would think about optimization, but in the case of a net in common a sport game, you would have only 2 nets in the field so you can allow yourself a lot more details in there.
In a game such as a soccer game, most of the physics related to the ball are put in the net and the ball itself so the load on the CPU even with lots of vertex in the net shouldn’t be a problem.
You will have to “cheat” a bit around the ball itself. The main error your could do is trying to set the ball to only follow a rigidbody dynamic force while, in actual implementation the ball only become “free” when it’s not in control or when it’s moving from a player to a target direction.
The cheat comes into 3 steps :
Make it so that the ball collision sphere can be changed via a simple call. It should be raised to 1.1 on all sides.
Create a collision zone inside the net that represents the “goal” line. Normally, you would already have such system in place for when there’s a goal, right? It’s just a small addition to it. Whenever the ball is within the “goal zone”, its sphere collider size is set to 1.1 in diameter which, if the model is 1.0 in size, will make it able to “push” the net without having its mesh actually crossing the edges in the models. Whenever the ball is reset or returned outside of the goal zone, its size return to the default 1.
For the stretching, there’s come the cheat… Whenever the ball is in the goal-zone, you can change the net’s cloth’s property in real-time. It does requires you to keep track of the ball’s speed which shouldn’t be much of a problem (as you only record the speed of 1 ball at the time).
So, when the ball is within the goal-zone at a speed that exceed some value you’ll have to test out (like 300000 units or something per seconds if 1 unit = 1m which is like 3km/h), you can set the Stretching Stiffness and Bending Stiffness values of the cloth to extremely sketchiness that, normally, would make your net look weird if kept as such. As the ball move “out” of the precise goal zone and as it “stretch” the net outside of the zone (behind it), you set it so that it return its value to default after 1 sec. This will allow the ball to be forced back and will return the net to its default state. As you might guess, this will require you to also keep a check as if the ball is in play or if it’s after a goal.
It’s really not that hard.
Keep track of the ball speed like 5 time per sec.
If the ball enter the goal zone, check if :
A) The ball is “free” (meaning not in the hands of the goaler for example).
B) The ball is moving above X units per sec.
C) There wasn’t any goal before entering the goal zone (like if the ball bounce from within the goal and return within the goal when the ball is moving around freely).
If all the points are good in 2), change the net’s cloth component values to allow it to be unrealistically stretchy. (If you must, turn off Use Tethers)
Once the ball move past the static goal zone, return the net’s cloth component value to its default over something like 1 sec. This will force the ball back in a relatively smooth curve. Also make sure the goal was registered so that the re-entry doesn’t trigger the net to be super-stretchy again.
If you “really” want to make sure the goal cloth completely recover from the “super stretch” state it pass through, you can actually store the “normal” net’s state through the Cloth component by storing its verticles through an array of vector3.
There’s not really a “way” of having spandex-ish simulation because an extended sketchiness bring one major flaw in 3D : The texture might gets stretched to a breaking point. To give you an idea, when a mesh deform, its displayed texture stretch, right? Now what would happen as the mesh stretch so much that some faces now have a UVs surface that skip many details? You will get some really glitchy shadow/light/glow effect. It’s especially true with a physical based material where many “part” of the shader is based on the relation between the UVs and the mesh’s lightning data.
Stretching Stiffness and Damping in the Cloth inspector come to mind.
But to get that level of deformation, you’re going to need a high-poly mesh. You might simply not have enough triangles for it to safely deform to the level you want.