Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Rope cutting with collision
#1
Hello, I've copied the code in another Post to implement cutting Rope with collision.
It does cut the rope, but some rope does not get cut.
Turn out when I check the debug.log, it always cut the Rope02, but when I check in Inspector, the actual Rope is colliding with the cutter is Rope.
This implies my method of specify the Rope from solver.simplices and solver.particleToActor return wrong result.
I'll attached the project, please take a look.
https://drive.google.com/file/d/12hSpnv0...sp=sharing

Please check this video for more info


Code:
        private void TryTearRope(Oni.Contact contact)
        {
            var collider= ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

            // get the particle index:
            var particleIndex = solver.simplices[contact.bodyA];

            // retrieve the actor this particle belongs to:
            var particleInActor = solver.particleToActor[particleIndex];
            var actor = particleInActor.actor;

            //collide with a cutter
            if (collider.TryGetComponent(out RopeCutter cutter))
            {   
                //check if contact with cuttable
                if (actor.TryGetComponent(out RopeCutComponent cuttable))
                {
                    var rope = cuttable.rope;
                    //pass all checks
                    Debug.Log($"cutter {cutter.name} cut the rope {rope.name} at particle {particleIndex}");
                    // check rope elements and tear the one that references this particle:
                    foreach (var elm in rope.elements)
                    {
                        if (elm.particle1 == particleIndex)
                        {
                            rope.Tear(elm);
                            rope.RebuildConstraintsFromElements();
                            break;
                        }
                    }
                }
            }
        }
Reply
#2
Hi!

If your ropes are using surface collisions (I'd be inclined to think they do, since they seem copied from the "RopeCutting" sample scene and the ropes in that scene use surface collisions), then you can't assume each simplex is made out of a single particle like you do here:


Code:
// get the particle index:
var particleIndex = solver.simplices[contact.bodyA];

This will lead to incorrect results.

The manual explains how to retrieve all particles in each simplex in the general case. See "Retrieving the particle involved in a contact":
http://obi.virtualmethodstudio.com/manua...sions.html

let me know if you need further help,

kind regards
Reply
#3
Thank you! After I change the code to this it works
Code:
            var collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;
            if (collider == null) return;

            // retrieve the offset and size of the simplex in the solver.simplices array:
            int simplexStart = solver.simplexCounts.GetSimplexStartAndSize(contact.bodyA, out int simplexSize);

            // starting at simplexStart, iterate over all particles in the simplex:
            int particleIndex = solver.simplices[simplexStart];

            // do something with each particle, for instance get its position:
            var particleInActor = solver.particleToActor[particleIndex];
            // retrieve the actor this particle belongs to:
            var actor = particleInActor.actor;

I've done a rope cut sequence for unlocking a chest. Any tips to improve will be appreciate!

Reply