Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Runtime repin rope to new controll point
#1
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
Reply


Messages In This Thread
Runtime repin rope to new controll point - by yeronimovr - 30-05-2021, 02:39 PM