Hey, am using the cloth physic to make a curtain and i want a collision between the player and curtain because i don’t want the curtain to be going through the player but my player is being instantiated at the start of the game so i can’t drag the player to the Capsule collider on the Cloth, is there any way i can do this please ?
Ok so i stumbled on this by accident but i’ve solved my problem and figure i post it here as well.
You can’t directly edit/change the colliders in the Cloth components array. So what you do is create a new capsuleCollider (or sphereCollider) array add the object you want assigned in that array. And then overwrite the Cloth components Collider array with the newly created array
void Start()
{
ClothRender = this.gameObject.GetComponent<Cloth>();
CapsuleSave = ClothRender.capsuleColliders;
}
void Update () {
if (ClothRender.capsuleColliders[0] == null)
{
PlayerCollider = GameObject.Find("ClothCollision");
CapsuleSave[0] = PlayerCollider .GetComponent<CapsuleCollider>();
ClothRender.capsuleColliders = CapsuleSave;
}
}
Hey,
I have the exact same problem so i can’t give you a answer. But i figure i give my 2 cents.
This is the script i have now that by my knowledge should just work, however it doesn’t
void Update () {
ClothRender = this.gameObject.GetComponent<Cloth>();
if (ClothRender.capsuleColliders[0] == null)
{
PlayerCollider = GameObject.Find("ClothCollision");
ClothRender.capsuleColliders[0] = PlayerCollider.GetComponent<CapsuleCollider>();
}
}
It gives no errors and seems to work but it just wont assign anything in the first slot. Despite if i drag it in myself and debug ClothRender.capsuleColliders[0] it returns the correct collider.