How to do it...

To use cloth simulation, follow these steps:

  1. Place the Flag game object in the scene.
  2. Add the Cloth component to the Flag game object (go to ComponentPhysicsCloth).
  1. Notice that a Skinned Mesh Renderer component is automatically added. You may remove the Mesh Renderer component from the object.
  2. Find the mesh of the Flag and drag it to the Mesh field in the Skinned Mesh Renderer component. If your game object still has the Mesh Filter component, you may click on the mesh attached to it and it will be displayed in the Project View. This makes it easier to find the mesh we need.
  3. If your game object still has the Mesh Filter component attached, you can remove it.
  4. You may need to add a material to the Flag game object. If it lacks the material, drag appropriate materials into the Materials section in the Skinned Mesh Renderer.
  5. Go to the Cloth component settings in the Inspector and click on the Edit Constraints button, as shown in the following screenshot:
Edit Constraints button
  1. The Cloth Constraints window will appear, as shown in the following screenshot:
Editing constraints
  1. It is used to constrain the cloth movement. To pin a cloth to something, select the Paint tab and click on the Max Distance checkbox. By left-clicking on a vertex, you can paint it red, which means its movement is fully constrained. You may choose a different color to make the cloth move slightly. Black means no constrains at all.
  2. After painting at least one vertex, you may switch to the Select tab. In this tab, you can box-select vertices. After selecting a group of vertices, you may check the Max Distance checkbox and edit the value for all selected vertices at once.
  3. If you cannot select or paint the vertices, rotate the viewyou may be looking at your mesh from the backfaces side. Selecting and painting works only on the frontfaces side, unless you check the Manipulate Backfaces option in the Visualization dropdown.
  4. Our Flag's orientation is top to bottom (it is pinned with its top to the pole). So we should select all top vertices and paint them red (set the Max Distance to 0). In your case, you may want to pin other vertices.
  5. To remove the constrain from any given vertex, select it (you need to be in the Select tab) and uncheck the Max Distance checkbox. The vertex will turn black, which means it is not constrained any more.
  6. To make the Flag collide with other game objects, go to the Capsule Colliders and Sphere Colliders array in the Cloth component's settings. You may add Sphere Colliders or Capsule Colliders located in the scene here. Cloth can collide only with those two types of colliders.
  7. Play the game to see the effect.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.63