Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  get sign when cloth is tore
#2
(07-03-2019, 10:20 AM)Richard Wrote: Hello.

I want to make if statement when the cloth is tore. How can I do that?

Hi,

You could constantly poll for a difference in used particles, but that's not very efficient. Using an event is much better.

I've modified ObiTearableCloth.cs to include an event callback when the cloth is torn, please find it attached. This event is passed the constraint and particle indices involved in the tear event by parameter.

Here's a usage example: this script subscribes to the callback event, and spawns a GameObject at the position of each torn particle.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiTearableCloth))]
public class ClothTornEvent : MonoBehaviour {

    ObiTearableCloth cloth;
    public GameObject thingToSpawn;

    void OnEnable () {
        cloth = GetComponent<ObiTearableCloth>();
        cloth.OnConstraintTorn += Cloth_OnConstraintTorn;
    }
    
    void OnDisable(){
        cloth.OnConstraintTorn -= Cloth_OnConstraintTorn;
    }
    
    void Cloth_OnConstraintTorn (object sender, ObiTearableCloth.ObiConstraintTornEventArgs e)
    {
        if (thingToSpawn != null)
            GameObject.Instantiate(thingToSpawn,cloth.Solver.positions[cloth.particleIndices[e.particleIndex]],Quaternion.identity);
    }
}


Attached Files
.cs   ObiTearableCloth.cs (Size: 25.02 KB / Downloads: 4)
Reply


Messages In This Thread
get sign when cloth is tore - by Richard - 07-03-2019, 10:20 AM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 11:05 AM
RE: get sign when cloth is tore - by Richard - 07-03-2019, 12:27 PM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 12:39 PM
RE: get sign when cloth is tore - by Richard - 07-03-2019, 01:10 PM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 01:48 PM
RE: get sign when cloth is tore - by Richard - 07-03-2019, 02:11 PM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 02:13 PM
RE: get sign when cloth is tore - by Richard - 07-03-2019, 02:34 PM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 02:49 PM
RE: get sign when cloth is tore - by Richard - 07-03-2019, 03:08 PM
RE: get sign when cloth is tore - by josemendez - 07-03-2019, 04:04 PM
RE: get sign when cloth is tore - by Richard - 11-03-2019, 03:16 AM
RE: get sign when cloth is tore - by josemendez - 11-03-2019, 08:41 AM
RE: get sign when cloth is tore - by Richard - 11-03-2019, 10:20 AM
RE: get sign when cloth is tore - by josemendez - 11-03-2019, 07:45 PM
RE: get sign when cloth is tore - by Richard - 12-03-2019, 11:21 AM
RE: get sign when cloth is tore - by josemendez - 12-03-2019, 11:25 AM