Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Cloth not responding to parts of ClothSphereColliderPair.

Discussion in 'Physics' started by YoungXi, Jun 20, 2017.

  1. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Just look at the picture:
    upload_2017-6-20_15-5-53.png

    The colliders are dynamically generated once based on the bone transforms. And are subdevided using a BVH method. But, when I set up the ClothSphereColliderPair[], the right legs colliders always fails.

    Here is the code how I setup and pass the ClothSphereColliderPair[] to the Cloth component:
    First, I already have SphereColliders[] colliders generated;

    private void CreateColliderPairs()
    {
    List<ClothSphereColliderPair> pair = new List<ClothSphereColliderPair>();

    for (int i = 0; i < refBonesCount; i++)
    {
    if (skinnedBVHs != null)
    {
    int parentId = skinnedBVHs.bvh.id;
    BVHNode<AABB>.Traverse(skinnedBVHs.bvh, (BVHNode<AABB> node) =>
    {
    if (node.id != parentId)
    {
    if (parentId == thighRIndex)
    {
    Debug.Log("skinnedBVH is thighR");
    }
    pair.Add(new ClothSphereColliderPair(colliders[node.id], colliders[parentId]));
    }
    });
    }
    }

    // If I only add the right legs' colliders in the hard coded way, it would work.
    //pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[pelvisIndex].bvh.id], colliders[skinnedBVHs[thighRIndex].bvh.id]));
    //pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[pelvisIndex].bvh.id], colliders[skinnedBVHs[thighLIndex].bvh.id]));
    //pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[thighLIndex].bvh.id], colliders[skinnedBVHs[calfLIndex].bvh.id]));
    //pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[thighRIndex].bvh.id], colliders[skinnedBVHs[calfRIndex].bvh.id]));

    colliderPairs = new ClothSphereColliderPair[pair.Count];
    pair.CopyTo(colliderPairs);
    }

    As you can see, the ClothSphereColliderPair is created into a List<>, and then copied to the colliderPairs, which is an array.

    And for the case to setup the collider pair to the cloth, simply do Cloth.sphereColliders = colliderPairs;

    I thought the Cloth component has a limit of 30 for the sphere collider pairs. Anyway my colliderPairs is definitely less than that.
     
  2. nbaris

    nbaris

    Joined:
    Jan 13, 2015
    Posts:
    18
    Were you able to figure this out? I have the same issue
     
  3. Cover-Club-Media

    Cover-Club-Media

    Joined:
    Apr 30, 2015
    Posts:
    77
    I found this happens when you overlap colliders like I see in your picture. I prefer capsules and I line up the ends like joints. I also add a bit more on my colliders to help and I try not to scale the transform as I thought it was doing odd things to the cloth.

    Last thing, I made a robe like that in your picture. It looks like you have a full front. I found it to be a huge pain(with world settings) and the result on my end was subpar compared to a robe with bathrobe type design. I redid all my characters with several styles of that kind of robe. Unity cloth is really great but it doesn't work well with some designs.

    Hopefully that helps you.
     
    nbaris likes this.
unityunity