Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Finding last point of rope
#30
(19-11-2021, 11:54 AM)srid96 Wrote: Could you explain it in code, that would help me understand better

It's basic programming stuff, really: remove the break; instruction (so that the loop continues after finding the cut), then for every element after the cut call DeactivateParticle on both its particles, and mark the element to later destroy it (for instance, by adding it to a list of elements to destroy).

Then for all elements marked for destruction, remove them from the rope.elements array.

In code:

Code:
// check rope elements and tear the one that references this particle:
bool torn = false;
List<ObiStructuralElement> toDestroy = new List<ObiStructuralElement>();
foreach (var elm in actor.elements)
{

      if (elm.particle1 == particleIndex)
      {
          actor.Tear(elm);
          torn = true;
      }

      // deactivate particles of all elements after the torn one:
      if (torn)
      {
           actor.DeactivateParticle(solver.particleToActor[elm.particle1].indexInActor);
           actor.DeactivateParticle(solver.particleToActor[elm.particle2].indexInActor);
           toDestroy.Add(elm);
       }
 }

// remove all elements past the torn one:
foreach (var elm in toDestroy)
   actor.elements.Remove(elm);

// update constraints:
if (torn)
    actor.RebuildConstraintsFromElements();

This is untested but should work. Note that removing the part of the rope after the cut immediately will make it look like the rope just got shorter.
It would look better if you stored the cut element, and after some time removed the bit of the rope that was cut off.
Reply


Messages In This Thread
Finding last point of rope - by srid96 - 15-11-2021, 07:36 AM
RE: Finding last point of rope - by josemendez - 15-11-2021, 08:40 AM
RE: Finding last point of rope - by srid96 - 15-11-2021, 09:08 AM
RE: Finding last point of rope - by josemendez - 15-11-2021, 09:21 AM
RE: Finding last point of rope - by srid96 - 15-11-2021, 03:35 PM
RE: Finding last point of rope - by josemendez - 15-11-2021, 03:39 PM
RE: Finding last point of rope - by srid96 - 15-11-2021, 03:42 PM
RE: Finding last point of rope - by josemendez - 15-11-2021, 03:47 PM
RE: Finding last point of rope - by srid96 - 16-11-2021, 08:30 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 08:39 AM
RE: Finding last point of rope - by srid96 - 16-11-2021, 09:10 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 09:48 AM
RE: Finding last point of rope - by srid96 - 16-11-2021, 10:39 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 10:49 AM
RE: Finding last point of rope - by srid96 - 16-11-2021, 10:57 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 10:59 AM
RE: Finding last point of rope - by srid96 - 16-11-2021, 11:18 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 11:22 AM
RE: Finding last point of rope - by srid96 - 16-11-2021, 11:42 AM
RE: Finding last point of rope - by josemendez - 16-11-2021, 11:44 AM
RE: Finding last point of rope - by srid96 - 18-11-2021, 02:39 PM
RE: Finding last point of rope - by josemendez - 18-11-2021, 02:48 PM
RE: Finding last point of rope - by srid96 - 18-11-2021, 04:07 PM
RE: Finding last point of rope - by josemendez - 19-11-2021, 09:06 AM
RE: Finding last point of rope - by srid96 - 19-11-2021, 10:14 AM
RE: Finding last point of rope - by josemendez - 19-11-2021, 10:22 AM
RE: Finding last point of rope - by srid96 - 19-11-2021, 11:29 AM
RE: Finding last point of rope - by josemendez - 19-11-2021, 11:43 AM
RE: Finding last point of rope - by srid96 - 19-11-2021, 11:54 AM
RE: Finding last point of rope - by josemendez - 19-11-2021, 12:24 PM
RE: Finding last point of rope - by srid96 - 19-11-2021, 01:39 PM
RE: Finding last point of rope - by josemendez - 19-11-2021, 02:22 PM
RE: Finding last point of rope - by srid96 - 19-11-2021, 06:45 PM