Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Climbing on rope and fix to move only on x, y
#11
I have a new issue:

If I cut the rope than the below scripts not give me the correct last particle position.

Can you help me in this?


private int GetFirstParticleIndex() => rope.elements[0].particle1;

private int GetLastParticleIndex() => rope.elements[rope.elements.Count - 1].particle2;


and

public void CutRopeAtIndex(ObiRope rope, int particleIndex)
{
    if ((DateTime.Now - _lastTimeCut).Milliseconds > 100)
    {
        if (particleIndex < rope.elements.Count)
            rope.Tear(rope.elements[particleIndex]);

        rope.RebuildConstraintsFromElements();
        _lastTimeCut = DateTime.Now;
    }
}


How can I get the cutted rope (that remains in the air, and not on the ground) last particle?
Reply
#12
When you cut a rope, the rope's last particle is still the same as it was before the cut. I mean, you still have only one rope, but with one discontinuity. Each piece after the cut is not an independent rope.

Cutting a rope at element "N", detaches the first particle of that element and creates a new second particle for the element before it. Like this:

O----O----O----O----O

Cut at element 2:

O----O----(O)    O----O----O

Depending on which half of the rope is still on the air, its last particle can either be "particle1" of the element you cut, or particle2 of the previous element.

Regarding your code, this is completely wrong:

Code:
rope.Tear(rope.elements[particleIndex]);

You can't access the elements array using a particle index. There's not the same amount of elements than particles, so this will often lead to an out of bounds access exception which you have checked for using the "if (particleIndex < rope.elements.Count) conditional". Furthermore, particles are rearranged whenever the rope is cut or resized, while elements are not. So after the first cut, this code will behave in very strange ways.

You need to pass an element index, not a particle index.
Reply
#13
(25-10-2021, 08:49 AM)josemendez Wrote: When you cut a rope, the rope's last particle is still the same as it was before the cut. I mean, you still have only one rope, but with one discontinuity. Each piece after the cut is not an independent rope.

Cutting a rope at element "N", detaches the first particle of that element and creates a new second particle for the element before it. Like this:

O----O----O----O----O

Cut at element 2:

O----O----(O)    O----O----O

Depending on which half of the rope is still on the air, its last particle can either be "particle1" of the element you cut, or particle2 of the previous element.

Regarding your code, this is completely wrong:

Code:
rope.Tear(rope.elements[particleIndex]);

You can't access the elements array using a particle index. There's not the same amount of elements than particles, so this will often lead to an out of bounds access exception which you have checked for using the "if (particleIndex < rope.elements.Count) conditional". Furthermore, particles are rearranged whenever the rope is cut or resized, while elements are not. So after the first cut, this code will behave in very strange ways.

You need to pass an element index, not a particle index.


Thanks. In the end it was simpler than I thought
I just created a lastParticle variant and that variant is the tear particle index. Gran sonrisa
Now it is working like a charm!
Reply
#14
(26-10-2021, 11:42 AM)лакасрак Wrote: Спасибо. В конце концов, это оказалось проще, чем я думал,
я только что создал вариант lastParticle, и этот вариант является индексом слезоточивых частиц. Gran sonrisa
Теперь он работает как шарм!
Please share the code if it's not too much troubl
Reply