Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Unpin Rope not working
#1
Hi, 
I've attached pin at both end of the rope. I want to unpin it from one of the ends.
I've tried the below code but nothing seems to be working. Its always pinned even after running the below code.
I've attached reference screenshot of what I am trying to do. 
Created 2 ropes and pinned them on the board. I want to unpin one end of the rope and pull the rope to the other knob using obiropecursor. (ChangeLength function).
Using ObiRopeCursor is the right approach here ?

Code:
var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
int batches = pinConstraints.batches.Count;
for (int j = 0; j < batches; j++)
{
    int count = pinConstraints.batches[j].constraintCount;
    Debug.Log("count : " + count);
    for (int i = 0; i < count; i++)
    {
        pinConstraints.batches[j].RemoveConstraint(i);
        pinConstraints.batches[j].RemoveFromSolver(null);
    }
    pinConstraints.RemoveBatch(pinConstraints.batches[j]);           
}
pinConstraints.RemoveFromSolver();

To test if cursor changeLength is working I manually disabled one of the pinned gameobject and tried the below code. ChangeLength function is also not working as expected.
Its pulling the rope only to some extent. After that rope got stiff and straightened. Attached screenshot.

Code:
private void Update()
  {
      if (knobDetached)
      {
          cursor.ChangeLength(rope.restLength - 30 * Time.deltaTime);
      }
  }

Note:
If I use ObiParticleAttachment instead of Pin Constraint, cursor changeLength is working as expected

Code:
private void RopeAttachment(ObiRope rope, ObiCollider bodyA, ObiCollider bodyB)
{
    attachment1 = rope.AddComponent<ObiParticleAttachment>();
    attachment1.target = bodyA.transform;
    attachment1.particleGroup = rope.blueprint.groups[0];
    attachment1.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;

    attachment2 = rope.AddComponent<ObiParticleAttachment>();
    attachment2.target = bodyB.transform;
    attachment2.particleGroup = rope.blueprint.groups[rope.blueprint.groups.Count - 1];
    attachment2.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
}


Attached Files Thumbnail(s)
       
Reply
#2
Hi!

Unless you've created your own constraints batch -I don't know if that's the case, since this code is only about removing constraints- there's no need to remove the entire batch from the solver: you can just remove individual constraints. There's also no need to remove the entire constraint type from the solver as you do in the last line.

However you do need to flag the constraints dirty so that any changes you make take effect. See "Adding/removing constraints" at the end of the following page:

http://obi.virtualmethodstudio.com/manua...aints.html

(05-06-2024, 08:27 AM)kripa1415 Wrote: ChangeLength function is also not working as expected.
Its pulling the rope only to some extent. After that rope got stiff and straightened. Attached screenshot.

This happens because the pin constraint hasn't been properly removed, so when you reduce the length of the rope it gets stretched into a straight line.

kind regards,
Reply
#3
Hi,

Called constraints dirty function.

Code:
// this will cause the solver to rebuild pin constraints at the beginning of the next frame:
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);

Its working now

Thanks!
Reply