15-05-2026, 04:36 AM
(08-05-2026, 12:03 PM)josemendez Wrote: Thanks! will take a look and get back to you asap.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;
}