22-02-2018, 08:58 AM
(This post was last modified: 22-02-2018, 08:59 AM by josemendez.)
(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 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
cheers!