Obi Official Forum
Help Runtime repin rope to new controll point - 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 Runtime repin rope to new controll point (/thread-2963.html)



Runtime repin rope to new controll point - yeronimovr - 30-05-2021

Hello, let`s say there are A and B points between which i`m generating a rope. Then i want to add a 3rd C point and then move/repin constraint rope to new C point. Below steps:

1. spawn rope between A-B: two controll points and 2 pin constraints 
2. spawn new game object and adding on his transform new controll point using InsertControlPoint
Code:
 Vector3 pointPos = GetSolverLocalPos(hooks[GetLastHookIndex].transform.position);
 rope.path.InsertControlPoint(rope.path.ControlPointCount - 1 ,pointPos, -startHook.position.normalized, pointPos.normalized, Vector3.up, .1f, 0.1f, colliderThickness, 0, Color.red, "Hook");

3. unsap (remove constraint) rope from B: getting rope consraint, getting first batch, removing from batch. set batch to solver, setDirtyConstraints
Code:
  var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
  var batch = pinConstraints.GetFirstBatch();
  int index = batch.constraintCount - 1;
           
  pinConstraints.RemoveFromSolver();
  batch.RemoveConstraint(index);
  pinConstraints.AddToSolver(solver);
  rope.SetConstraintsDirty(Oni.ConstraintType.Pin);

and now where im stuck:
4. i want to move rope (all particles to new C point position) forward C - it works
Code:
for (int i = 0; i < blueprint.activeParticleCount; i++)
        {
            rope.TeleportParticle(rope.solverIndices[i], GetSolverLocalPos(hooks[GetLastHookIndex].transform.position));
            rope.solver.velocities[i] = Vector4.zero;
            rope.solver.angularVelocities[i] = Vector4.zero;
        }
        rope.UpdateParticleProperties();
        rope.RecalculateRestPositions();
        rope.RecalculateRestLength();

5. when i want to pin last particle to C rope the constraint doesnt work and rope is going back with all forces working on particles - stuck here.
Code:
var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
        var batch = pinConstraints.GetFirstBatch();

        pinConstraints.RemoveFromSolver();

        batch.AddConstraint(rope.solverIndices[blueprint.activeParticleCount - 1], lastHook.AttachCollider, Vector3.zero, Quaternion.identity, 0, 0, float.PositiveInfinity);
        batch.activeConstraintCount = 2;

        pinConstraints.AddBatch(batch);
        pinConstraints.AddToSolver(solver);

        rope.SetConstraintsDirty(Oni.ConstraintType.Pin);

My target is to attach rope to new C point, set there cursor, change rope length that i can again attach rope to B point getting: A-C-B connections.

Which steps i`m missing (some update on some component) or what im doing wrong ? Thanks for any help in advance


RE: Runtime repin rope to new controll point - josemendez - 31-05-2021

Code:
for (int i = 0; i < blueprint.activeParticleCount; i++)
{
rope.TeleportParticle(rope.solverIndices[i], GetSolverLocalPos(hooks[GetLastHookIndex].transform.position));
rope.solver.velocities[i] = Vector4.zero;
rope.solver.angularVelocities[i] = Vector4.zero;
}

This will place all particles in the rope at the exact same position, essentially collapsing the rope in to a point. I guess this is not what you want in this particular case. Not sure what the intent is?


When adding the new pin constraint to point C, you set the amount of active constraints to 2, despite only adding 1:
Code:
batch.activeConstraintCount = 2;

Does that batch already contain a constraint that you also want active?

Other than this, the code looks ok to me.