Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Finding last point of rope
#21
Hi Again Sonrisa ,

So I am using Tear() function to rope am using, once the rope is torn how to find last point of new torn rope(first rope). 

My rope is attached to a gameobject which moves, so also, once rope is torn, how to ignore second rope completely (it drags since its parented to that gameobject)
Reply
#22
(18-11-2021, 02:39 PM)srid96 Wrote: Hi Again Sonrisa ,

So I am using Tear() function to rope am using, once the rope is torn how to find last point of new torn rope(first rope). 

Hi!

You can detect all torn points by simply iterating trough rope elements until you find an element such that:

Code:
element.particle2 != nextElement.particle1


(18-11-2021, 02:39 PM)srid96 Wrote: My rope is attached to a gameobject which moves, so also, once rope is torn, how to ignore second rope completely (it drags since its parented to that gameobject)

Keep in mind that simulation is always performed in the solver's local space. From the manual:

Quote:Solvers always perform the simulation in local space. This means that translating, rotating or scaling the solver will rigidly transform the simulation as a whole.


The torn bit of rope should not move unless you're simulating in the rope's local space (that is, you placed the ObiSolver and the ObiRope in the same object).

Simply place the solver outside the object's hierarchy.

kind regards,
Reply
#23
(18-11-2021, 02:48 PM)josemendez Wrote: Hi!

You can detect all torn points by simply iterating trough rope elements until you find an element such that:

Code:
element.particle2 != nextElement.particle1



Keep in mind that simulation is always performed in the solver's local space. From the manual:



The torn bit of rope should not move unless you're simulating in the rope's local space (that is, you placed the ObiSolver and the ObiRope in the same object).

Simply place the solver outside the object's hierarchy.

kind regards,

My rope resizes its length over time, so by ignoring I mean getting rid of that part . So, when torn, rope length from the first piece resizes.

Taking out solver from object's hierarchy does the trick for the torn piece not to follow, when rope's particle attachment target set to that object. Doing this, rope length's reduces the torn piece first and then first piece. But i am focusing only on first piece.
Reply
#24
(18-11-2021, 04:07 PM)srid96 Wrote: My rope resizes its length over time, so by ignoring I mean getting rid of that part . So, when torn, rope length from the first piece resizes.

Depends on where you place the cursor. If you place it at a particle in the first piece, it will resize the first piece. You can place cursors anywhere along the rope, oriented in either direction.
Reply
#25
am calculating rope' length in update function, if its less than 1, my game is over, something like that. Thats why i need to get rid of the torn piece, as in it doesn't depend on anything, not just resizing from cursor point. Sorry i wasnt clear.
Reply
#26
(19-11-2021, 10:14 AM)srid96 Wrote: am calculating rope' length in update function, if its less than 1, my game is over, something like that. Thats why i need to get rid of the torn piece, as in it doesn't depend on anything, not just resizing from cursor point. Sorry i wasnt clear.

Oh, ok. You can just remove the elements in the second piece, deactivating all particles referenced by these elements by calling rope.DeactivateParticle(index) and passing the index of the particle in the rope.
Reply
#27
(19-11-2021, 10:22 AM)josemendez Wrote: Oh, ok. You can just remove the elements in the second piece, deactivating all particles referenced by these elements by calling rope.DeactivateParticle(index) and passing the index of the particle in the rope.
For Tearing Code :
Code:
        // check rope elements and tear the one that references this particle:
        foreach (var elm in actor.elements)
        {
            if (elm.particle2 == particleIndex)
            {
                actor.Tear(elm);
                actor.RebuildConstraintsFromElements();
                DeactivateTornParticles(particleIndex);
                break;
            }
        }


For deactivation of particles in second piece:
Code:
    private void DeactivateTornParticles(int particleIndex)
    {
        for(int i = particleIndex; i < rope.elements.Count; i++)
        {
            rope.DeactivateParticle(i);
        }
    }

rope doing something weird, its like trying attach the cut portion, stretches long
Reply
#28
(19-11-2021, 11:29 AM)srid96 Wrote:
Code:
private void DeactivateTornParticles(int particleIndex)
    {
for(int i = particleIndex; i < rope.elements.Count; i++)
        {
rope.DeactivateParticle(i);
        }
    }

rope doing something weird, its like trying attach the cut portion, stretches long

You're mixing up particles and elements again: it does not make sense to iterate from particleIndex to the number of elements. There's a different number of elements than particles, and they're in different order. Element number 6 in the elements array might reference particles 24 and 65. You can't assume particle #6 is part of element #6.

Iterate trough elements past the (elm.particle2 == particleIndex) one, and for each element deactivate both particles. Then remove all those elements from the elements array.
Reply
#29
Could you explain it in code, that would help me understand better
Reply
#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