Obi Official Forum
Bug / Crash Rope cutting with collision - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Bug / Crash Rope cutting with collision (/thread-3950.html)



Rope cutting with collision - spikebor - 31-07-2023

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/12hSpnv0v2i0Tcwye-diDejfGeRmE_aGC/view?usp=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;
                        }
                    }
                }
            }
        }



RE: Rope cutting with collision - josemendez - 31-07-2023

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/manual/6.3/scriptingcollisions.html

let me know if you need further help,

kind regards


RE: Rope cutting with collision - spikebor - 31-07-2023

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!