Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manual tearing via cript
#1
How do i tear the rope manually via script at one certain particle?
Reply
#2
(09-10-2017, 10:29 AM)Kalidor Wrote: How do i tear the rope manually via script at one certain particle?

All you have to do is call Tear(constaintIndex) on the rope script. Constraints are in between the particles, so if your rope has particles 0-20 the constraint indices will be 0-19. I found that the rope don’t like to be cut at 0 nore the last constraint. I get an out of range error when cutting the last constraint. Could be other code of mine messing it up, but just a heads up. Also make sure you have particles in your pool. Each cut needs one extra particle.
Reply
#3
Dedo arriba 
(09-10-2017, 11:32 AM)niZmo Wrote: All you have to do is call Tear(constaintIndex) on the rope script. Constraints are in between the particles, so if your rope has particles 0-20 the constraint indices will be 0-19. I found that the rope don’t like to be cut at 0 nore the last constraint. I get an out of range error when cutting the last constraint. Could be other code of mine messing it up, but just a heads up. Also make sure you have particles in your pool. Each cut needs one extra particle.

This. I couldn't have explained it better.

We should probably be checking that the range is correct inside Tear(), since tearing a constraint splits one of the particles at its ends: which one? the one with more mass, or a random one if both have the same. Torn particles (the original one and the new one added at the cut) then have their mass halved.

 In the edges of the rope of course, this can cause a cut to attempt to create an additional particle at the very beginning/end of the rope, which is illegal. We check for this whenever we use Tear() inside Obi, but it being a public function we should really perform the check inside of it. 

Thanks for pointing it out niZmo.
Reply
#4
When i call Tear(1) on the top rope, the physics of the other particles is missing:

[Image: rope.gif]

Any help?
Reply
#5
(10-10-2017, 09:56 AM)Kalidor Wrote: When i call Tear(1) on the top rope, the physics of the other particles is missing:

[Image: rope.gif]

Any help?

The first two particles in that particular rope are fixed (i.e., they have infinite mass). When you call Tear(1) in a segment whose two particles at its ends have infinite mass, the mass of the particle that is cut in half is also halved. This results in a new particle has has infinite/2 = infinite mass. So this particle is so heavy that will fall to the ground regardless of any constraints.

Solutions: Don't call Tear() in a segment that joins two fixed particles, or if you do, modify the mass of the newly spawned particle after you call Tear().
Reply
#6
There is the same behaviour, when i tear the rope at the middle.
The neighboring particles are not fixed.
Reply
#7
(10-10-2017, 11:51 AM)Kalidor Wrote: There is the same behaviour, when i tear the rope at the middle.
The neighboring particles are not fixed.

Works fine for me, this is the code I´m using:

Code:
    
void Update () {
    if (Input.GetKeyDown(KeyCode.A)){

        Obi.ObiRope rope = GetComponent<ObiRope>();
        
        rope.DistanceConstraints.RemoveFromSolver(null);
        rope.BendingConstraints.RemoveFromSolver(null);

        rope.Tear(2);

        rope.BendingConstraints.AddToSolver(this);
        rope.DistanceConstraints.AddToSolver(this);
    
        // update active bending constraints:
        rope.BendingConstraints.SetActiveConstraints();
    
        // upload active particle list to solver:
        rope.Solver.UpdateActiveParticles();
    }
}

Make sure that you're removing the constraints previous to calling Tear(), and adding them back in afterwards. This should always be done when you add/remove constraints at runtime, no matter if you use Tear() or do the changes manually.

See:
http://obi.virtualmethodstudio.com/tutor...aints.html
Reply
#8
Great, thank you!

I wasn't aware of adding/removing the constraints.
Reply
#9
Hi,

Your code for tearing works perfectly, but after performing a manual tear, the ropes still attached to a moving object will start behaving erratically.
I think its because there is no RigidBody in the teared end of the rope.

This is the behaviour: https://youtu.be/yUacjVmLiTk


My question is: How do I attach (or instantiate) a new handle in the new (teared) end of both broken ropes. Via script?

Thank you,
Nestor
Reply
#10
(19-10-2017, 11:12 AM)x-lab Wrote: Hi,

Your code for tearing works perfectly, but after performing a manual tear, the ropes still attached to a moving object will start behaving erratically.
I think its because there is no RigidBody in the teared end of the rope.

This is the behaviour: https://youtu.be/yUacjVmLiTk


My question is: How do I attach (or instantiate) a new handle in the new (teared) end of both broken ropes. Via script?

Thank you,
Nestor

Hi,

Are you using tether constraints?
Reply