Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding pin constraint to particle in runtime.
#5
(09-11-2017, 12:57 AM)niZmo Wrote: Oh i didn't see the // lol. And now i see the other code that's commented out that you need. Try to remove the particle from the particle handle first with RemoveParticle(index), then pin the particle. Look at the first link snippet i sent you, to see what methods you need to call before and after. You have them in there already, RemoveFromSolver and PushDataToSolver.

More info here.

My current code:

Code:
private void AttachHook()
    {
        var particleIndex = _obiParticleHandle.FirstParticleIndex;


        _obiParticleHandle.RemoveParticle(particleIndex);

               // Disabling or enabling _obiParticleHandle has no affect
        _obiParticleHandle.enabled = false;

        ObiPinConstraintBatch pinBatch = obiRope.PinConstraints.GetBatches()[0] as ObiPinConstraintBatch;

        obiRope.PinConstraints.RemoveFromSolver(null);

        pinBatch.AddConstraint(obiRope.particleIndices[particleIndex], obiColliderToAttach, obiOffsetToAttach, 0);
        

        obiRope.PinConstraints.AddToSolver(null);
        obiRope.PinConstraints.PushDataToSolver();
    }

'ObiParticleHandle.RemoveParticle(index)' is working and was really helpfull, thanks.

But complete code is not working still.
After calling 'obiRope.PinConstraints.AddToSolver(null)' really weird things happen.
I am not sure how to describe it but rope starts moving up and down super fast, looks like it has infinite length.


When I comment 'obiRope.PinConstraints.AddToSolver(null)' line rope behaves ok. But again while I can see newly created PinConstraint in unity inspector rope behaviour looks like no particle has PinConstraint attached.
Reply


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