Obi Official Forum
Help Rope Cut not working - 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: Help Rope Cut not working (/thread-4244.html)



Rope Cut not working - kripa1415 - 07-06-2024

Hi,
 I've attached video reference here of what happened while trying to cut the rope.
 I've used RopeSweepCut. Its working in the sample scene. But If I use the same script for my Rope which is created dynamically at runtime, it not working.
 When I swipe to cut, I can see the line renderer and on release, there's a shake happening in rope but its not actually cutting the rope.
 I added log inside the below function. Log printed as expected but cut doesn't work

https://drive.google.com/file/d/1EqPp-hm1m2P1aJTCIJcBuBhAjY_67DrC/view?usp=sharing

Code:
private void ScreenSpaceCut(Vector2 lineStart, Vector2 lineEnd)
{
    // keep track of whether the rope was cut or not.
    bool cut = false;

    // iterate over all elements and test them for intersection with the line:
    for (int i = 0; i < rope.elements.Count; ++i)
    {
        // project the both ends of the element to screen space.
        Vector3 screenPos1 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle1]);
        Vector3 screenPos2 = cam.WorldToScreenPoint(rope.solver.positions[rope.elements[i].particle2]);

        // test if there's an intersection:
        if (SegmentSegmentIntersection(screenPos1, screenPos2, lineStart, lineEnd, out float r, out float s))
        {
            cut = true;
            rope.Tear(rope.elements[i]);
            Debug.Log("cut");
        }
    }

    // If the rope was cut at any point, rebuilt constraints:
    if (cut) rope.RebuildConstraintsFromElements();
}



RE: Rope Cut not working - josemendez - 07-06-2024

Hi,

Without taking a look at the code used to create your rope, it is not possible to debug this. Could you share your code?

Also keep in mind that the code used in the sample scene assumes the solver is at the scene's origin (solver-space data is not converted to world-space, as you can see in the code).

kind regards,


RE: Rope Cut not working - kripa1415 - 07-06-2024

Hi,
 pooledParticles was the problem. It was set to 0
 
Code:
// Setup a blueprint for the rope:
var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.resolution = 0.65f;
blueprint.thickness = 0.45f;
blueprint.pooledParticles = 0;


Changing this to 100 solved the problem.

Code:
blueprint.pooledParticles = 100;



RE: Rope Cut not working - josemendez - 07-06-2024

Glad to hear you found the issue! Sonrisa

Pooled particles are used when resizing and/or tearing the rope. They are initially inactive, and the rope uses them when there's a need to add new particles at runtime. Each cut consumes one particle from the pool, so with a size of 100 (which is the default when creating a rope via editor) the rope will be able to be cut 100 times before running out of particles.

kind regards,


RE: Rope Cut not working - kripa1415 - 07-06-2024

Hi,
 Ah okay. Got it!. Thanks
 I have one more requirement. 
 https://drive.google.com/file/d/1867Exn36lLioxee40FixV4LdmAy3YH1F/view?usp=sharing 

 I have knob attached at both ends of the rope.. After cutting the rope, I am using ObiRopeCursor to pull the rope. What I actually want is both knobs to pull the rope. After cutting, each knob has its own rope. So I want both knobs to pull the rope at the same time. Is this possible ?


RE: Rope Cut not working - josemendez - 07-06-2024

(07-06-2024, 09:02 AM)kripa1415 Wrote: After cutting, each knob has its own rope.

Technically it's still a single rope, just cut in two parts.

(07-06-2024, 09:02 AM)kripa1415 Wrote: []So I want both knobs to pull the rope at the same time. Is this possible ?

Simplest way to do this would be to set the rope's stretching scale parameter towards zero. This would shrink the entire rope, causing both halves of it to collapse towards the knobs.