Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding pin constraint to particle in runtime.
#1
Hi.
I have existing rope with couple on handlers on both of rope ends (attached to first and last rope particle).
I want to substitute them (or possibly only one of them with pin constraint).
I think handle can be removed/added with the help of disabling/enabling handle gameObject.
For adding ping constraint I'm launching some variations of following coroutine:
Code:
private IEnumerator AttachHook(){
        yield return 0;

        // Pin both ends of the rope (this enables two-way interaction between character and rope):
        ObiPinConstraints pinConstraints = obiRope.GetComponent<ObiPinConstraints>();
        ObiPinConstraintBatch pinBatch = pinConstraints.GetBatches()[0] as ObiPinConstraintBatch;

        // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it.
//        pinConstraints.RemoveFromSolver(null);
        
        // remove the first constraint.
//        pinBatch.RemoveConstraint(0);
        
        pinBatch.AddConstraint(obiRope.particleIndices[_obiParticleHandle.FirstParticleIndex], obiColliderToAttach, obiOffsetToAttach, 0);
        
        // Add the rope to the solver to begin the simulation:
        pinConstraints.AddToSolver(null);
//        pinConstraints.PushDataToSolver();
        
    }    

I was experimenting with Adding/Removing from solver and with pushing data back to solver without success.
I can see generated with script pin constraint in unity inspector, but it does nothing.
What am I missing?
Should I reinitialize rope somehow?

Thanks a lot.
Reply


Messages In This Thread
Adding pin constraint to particle in runtime. - by aaamarkin - 08-11-2017, 09:02 PM