Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Adding & Removing ObiParticleAttachments at runtime
#1
I want to dynamically add and remove ObiParticleAttachments to individual particles of Softbodies at runtime.
My current implemenation looks like this:


Code:
private void Grasp(ObiActor actor, int index)
        {
          attachment = actor.gameObject.AddComponent<ObiParticleAttachment>();
            attachment.target = transform;
            attachment.particleGroup = actor.blueprint.AppendNewParticleGroup(groupName);
            groupIndex = actor.blueprint.groups.Count;
            attachment.particleGroup.particleIndices = new List<int> { index };
            attachment.compliance = 0;
            attachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
            IsGrasping = true;

            solver.RemoveActor(actor);
            solver.AddActor(actor);
        }

private void Release()
        {
            Destroy(attachment);
            actor.blueprint.RemoveParticleGroupAt(groupIndex);
            solver.RemoveActor(actor);
            solver.AddActor(actor);
        }




I can succesfully preform Grasp() and Release() once. The second time I call Grasp() the actor moves only halfway to the attachments target. It seems like the solver did not fully forget the previous attachments.

I experimented several hours with the methods suggested in Scripting Constraints tutorial without success.

I don't want to add forces to particles in this script as it is done in ObiParticleDragger but rather activate & deactivate a pin/attachment constraint.

Thank you so much for your support!


tl/dr:
How do I properly register and unregister ObiParticleAttachments at runtime?
Reply


Messages In This Thread
Adding & Removing ObiParticleAttachments at runtime - by MartinBischoff - 04-03-2021, 03:20 PM