Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About PinConstraint Scripting
#2
(21-02-2018, 09:49 PM)Cannias Wrote: Hey there!

I want to snap the ObiRope to the block i have in scene in runtime. I can snap one end of the ObiRope but the other end of ObiRope doesn't seem to be working Gran sonrisa  i simply check for conditions (collider trigger, onMouseUp, etc.) and remove the PinConstraint from Spheres then add new PinConstraint to the block



As you can see in the video, white sphere (which is Pinned to the first particle) does what i want but the black one doesn't. I can't get the last particle of ObiRope. Here's my code for snapping:
Code:
       int addIndex; //Index of particle which i add PinConstraint (to block)
       int removeIndex; //Index of particle which i remove PinConstraint (from sphere)
       if (gameObject.name == "WhiteSphere")
       {
           //Remove the second PinConstraint & add PinConstraint to the first particle
           addIndex = 0;
           removeIndex = 1;
       }
       else
       {
           //Remove the first PinConstraint & add PinConstraint to the last particle
           addIndex = obiRope.UsedParticles;
           removeIndex = 0;
       }

       obiRope.PinConstraints.RemoveFromSolver(null);
       ObiPinConstraintBatch batch = (ObiPinConstraintBatch)obiRope.PinConstraints.GetBatches()[0];
       batch.RemoveConstraint(removeIndex);
       batch.AddConstraint(addIndex, blockObiCollider, new Vector3(0.8f, 0, 0), 1);
       obiRope.PinConstraints.AddToSolver(null);

Thanks in advance!

last particle addIndex should be  obiRope.UsedParticles-1. Arrays run from 0 to size-1  Guiño

cheers!
Reply


Messages In This Thread
About PinConstraint Scripting - by Cannias - 21-02-2018, 09:49 PM
RE: About PinConstraint Scripting - by josemendez - 22-02-2018, 08:58 AM
RE: About PinConstraint Scripting - by Cannias - 22-02-2018, 07:50 PM
RE: About PinConstraint Scripting - by josemendez - 22-02-2018, 08:20 PM
RE: About PinConstraint Scripting - by Cannias - 22-02-2018, 09:18 PM