Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Adding attachments at runtime to a pre-existing instance of a rope in 5.X
#1
I have been trying to figure out how to do this for a few hours now and I don't feel any closer than where I started.

I have a scene which is planned to have many ropes placed via the scene editor, many of them potentially sharing the same rope blueprints. Currently, my scene only has a single rope which has a static attachment to a floating cube. During runtime, I am attempting to add a pin constraint to an ObiCollider that collides with a given rope. I tried to adapt the grappling hook code into a method which is called when a rope collision event is triggered, and have verified that it is being called with the correct object references.

Code:
 private bool hasConstraint = false;

 public void OnRopeCollision(ObiRope rope, int ropeIndex) {
   if (hasConstraint) {
     return;
   }

   hasConstraint = true;
   var blueprint = rope.ropeBlueprint;
   var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin)
                            as ObiConstraints<ObiPinConstraintsBatch>;
   ObiPinConstraintsBatch batch = pinConstraints.GetFirstBatch();
   batch.AddConstraint(ropeIndex, _obiCollider, transform.localPosition, Quaternion.identity);
   batch.activeConstraintCount++;
    rope.ropeBlueprint = blueprint;
   _obiCollider.Phase = 1;
 }

I suspect the problem has to do with the way that the blueprint is instantiated versus the grappling hook sample, but I am really at a loss on how to debug this. Also, given that in the future, many ropes would potentially share the same blueprint, my intuition tells me that even if it did work, every single rope in the scene would become pinned to the ObiCollider.

Please let me know if you need any more information! Thank you for your help.
Reply


Messages In This Thread
Adding attachments at runtime to a pre-existing instance of a rope in 5.X - by eliza - 06-05-2020, 01:56 AM