Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Issues with closed loops
#8
(15-05-2026, 04:36 AM)N_U_P Wrote: I think I figured out an alternate way to do what I want to do, but I'm having trouble with what I think might be pretty basic ObiRope functionality, so sorry if this is a really basic question.

What I'm now trying to do is the following: I have a not closed rope that deforms during run time (including getting elongated and shrunk using a cursor). I would like to call a function during runtime that closes the rope (without changing anything else). The ends of the rope are very close to each other when I call this function, so there should not be a huge visible change. The way I'm trying to do it is to create a new blueprint during runtime using the rope's shape, close that blueprint, and then assign that blueprint to the rope. I could be messing up more than I know, but at the very least my particle positions seem to be wrong, because the rope teleports a short distance away when I call my function (my previous issues are not happening though which is good). I've been looking at different resources for guidance, but mostly this page Obi Physics for Unity - Scripting Particles and this thread Manually Placing Rope Particles. I have attached the code for my function to this reply. I appreciate all your help and apologies if I'm misunderstanding something basic.


Code:
void Generate()
{

    ObiParticleAttachment[] nodes = rope.GetComponents<ObiParticleAttachment>();
    nodes[0].enabled = false;
    nodes[1].enabled = false;

    // Calculate control point positions and tangent vector:
    Vector3 startPositionLS;
    Vector3 endPositionLS;
    Vector3 tangentLS;

    // Create the blueprint:
    var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();

    // Build the rope path:
    int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);

    ObiActor actor = rope.GetComponent<ObiActor>();

    for (int i = 0; i < actor.activeParticleCount - 1; ++i)
    {

        // retrieve the particle index in the solver:
        int solverIndex = actor.solverIndices[i];
        startPositionLS = actor.solver.positions[solverIndex];
        endPositionLS = actor.solver.positions[solverIndex + 1];

     
        tangentLS = (endPositionLS - startPositionLS).normalized;
        blueprint.path.AddControlPoint(startPositionLS, -tangentLS, tangentLS, Vector3.up, 0.1f, 0.1f, 1, filter, Color.white, "start");
    }

    startPositionLS = actor.solver.positions[actor.activeParticleCount];
    endPositionLS = actor.solver.positions[0];
    tangentLS = (endPositionLS - startPositionLS).normalized;
    blueprint.path.AddControlPoint(startPositionLS, -tangentLS, tangentLS, Vector3.up, 0.1f, 0.1f, 1, filter, Color.white, "start");


    blueprint.path.FlushEvents();
    blueprint.path.Closed = true;

    // Generate particles/constraints:
    blueprint.GenerateImmediate();

    // Set the blueprint:
    rope.ropeBlueprint = blueprint;
}

Hi,

There’s a couple problems with your code. The most important one is that it disregards vector spaces, assuming all data is expressed in world space.

Solver data is expressed in the solver’s local space:
https://obi.virtualmethodstudio.com/manu...icles.html

“ All spatial properties (positions, orientations, velocities, vorticities, etc) are expressed in the solver's local space.”

Conversely, blueprint data (since they’re assets, and hence not tied to a particular scene) is expressed in object space, just like mesh data in Unity.

Since you’re mixing solver and blueprint data, you should use Unity’s Transform and InverseTransform family of methods to convert all data to the same space:
https://docs.unity3d.com/6000.4/Document...sform.html

Specifically, you must convert the solver particle positions to the target rope’s local space while assigning them.


The second issue is that you’re assuming particles appear in the rope’s arrays in the same order they’re physically laid out in the rope. This is seldom the case, you should use elements instead:
https://obi.virtualmethodstudio.com/manu...ropes.html


Let me know if you need further help,

Kind regards,
Reply


Messages In This Thread
Issues with closed loops - by N_U_P - 02-05-2026, 03:32 AM
RE: Issues with closed loops - by josemendez - 06-05-2026, 08:33 AM
RE: Issues with closed loops - by josemendez - 06-05-2026, 09:10 AM
RE: Issues with closed loops - by josemendez - 06-05-2026, 10:13 AM
RE: Issues with closed loops - by N_U_P - 06-05-2026, 07:45 PM
RE: Issues with closed loops - by josemendez - 08-05-2026, 12:03 PM
RE: Issues with closed loops - by N_U_P - 15-05-2026, 04:36 AM
RE: Issues with closed loops - by josemendez - 15-05-2026, 09:26 AM
RE: Issues with closed loops - by N_U_P - 17-05-2026, 07:22 AM