Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi rope deleteingt cutted part after cut?
#6
Here's working code to remove part of the rope after a cut. I've subscribed to the rope's OnRopeTorn event, there I remove all elements after the cut.
The only caveat is when iterating trough elements and removing them, you must iterate backwards to avoid skipping over elements.

Code:
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiRope))]
public class DestroyTorn : MonoBehaviour
{
    void Start()
    {
        GetComponent<ObiRope>().OnRopeTorn += DestroyTeared_OnRopeTorn;
    }

    private void DestroyTeared_OnRopeTorn(ObiRope rope, ObiRope.ObiRopeTornEventArgs tearInfo)
    {
        for (int i = rope.elements.Count-1; i >= 0; --i)
        {
            var elm = rope.elements[i];

            rope.DeactivateParticle(rope.solver.particleToActor[elm.particle2].indexInActor);
            rope.elements.RemoveAt(i);

            if (elm == tearInfo.element)
                break;
        }

        rope.RebuildConstraintsFromElements();
    }

}
Reply


Messages In This Thread
RE: Obi rope deleteingt cutted part after cut? - by josemendez - 28-06-2021, 09:35 AM