Search Unity

Cloth don't interact with prefabs GameObjects

Discussion in 'Physics' started by kaisersam, Jun 10, 2016.

  1. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Hello guys,

    i just start to create a basketball shoot game.

    So i use cloth component for the net. After setting up it works fine. The problem is that the cloth don't interact with the balls (GameObject Prefabs).

    But when i create a sphere in the scene (with rigidbody and sphere collider, like GameObject prefab), the cloth interact with the sphere.

    How can i make the cloth interact with prefab GameObject?

    Thanks! :)

    Regards, Sam.
     
  2. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    in the collision detection (rigidbody panel), i select continious dynamic, but nothing change...

    It works only with the balls present in the scene. How can it works with a prefab object?
     
  3. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    There are two types of cloth in Unity, the Cloth (fast) component and the Interactive Cloth (slow) component. On the Cloth component you have to attach your collider to the Cloth, to define that the collider can interact with the Cloth. The Cloth inspector window has an array for the possible colliding collider.
    The interactive cloth is more expensive (cloth simulation), it collides without attaching the colliders on it.
     
  4. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    how can i use the interactive cloth?

    because i want my cloth (basketball net) to collide with prefabs object (it's not on the scene so i can't attach my collider prefab).
     
  5. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    can i use the script from unity 4 that used for "interactive cloth" and copy paste it in my unity version?
     
  6. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    any help?
     
  7. jumanahalasadi

    jumanahalasadi

    Joined:
    Dec 26, 2017
    Posts:
    3
    Hi i just solved this.

    First you declare an array of capsule colliders
    public CapsuleCollider[] colliders;

    then you call this code in any function when instantiating the prefab

    ///////
    Cloth b = Object.GetComponentInChildren<Cloth> (); //get the cloth from the gameobject
    colliders = new CapsuleCollider[4]; // can be any size you like

    //set the colliders from the gameobjects in the scene

    colliders[0] = GameObject.Find ("QuickRigCharacter_LeftUpLeg").GetComponent<CapsuleCollider>();
    colliders[1] = GameObject.Find ("QuickRigCharacter_RightUpLeg").GetComponent<CapsuleCollider>();
    colliders[2] = GameObject.Find ("QuickRigCharacter_LeftLeg").GetComponent<CapsuleCollider>();
    colliders[3] = GameObject.Find ("QuickRigCharacter_RightLeg").GetComponent<CapsuleCollider>();

    //set the collider array of the cloth to the array you just created
    b.capsuleColliders = colliders;