In Unity 3D, if you wish to add interactive cloth in your scene, most probably you need bring in some anchor points, which instruct the cloth which site remains static and fixed. This is a tedious task, and the process may involve:
- Add new GameObjects (Menu GameObject > Create Empty Object)
- For each game object, add a collider component (Menu Component > Physics > Box Collider)
- For each collider, specify the center and size of the collider
- For each collider, specify the 3D location of collider, at which the cloth remains static
- Make sure the collider overlaps/intersects with the cloth, otherwise, it won’t work. You might wish to calculate it carefully yourself!
What this post is trying to make, is to automatically introduce such anchor points to rectangular cloth (or rectangle mesh), and does all above programmatically, with configurable settings to add 1, 2, 3, and 4 anchors.
Usage: drag and associate the script (link below) to the cloth object in the scene hierarchy, and select which anchor (1, 2, 3, 4) you wish to add. That is it.
Now you don’t need to manually add colliders and even if your interactive cloth changes in location, rotation or even scaled! The script does all for you! Download the C# Script CornerAnchorForRectCloth.cs and happy coding!