11-08-2023, 05:59 PM
(This post was last modified: 11-08-2023, 06:03 PM by Alexander34.)
(09-08-2023, 07:18 AM)josemendez Wrote: Why would it be costly to create particle groups on the fly? they're a very small/simple object with a list of particles, and in the case of ropes they always contain just one index.Thanks, it's roughly clear how I can make the particles between two groups of particles stationary, as in the screenshot in the hat. So that we hold on to the rope with our hands and this segment all the way down to our feet is stretched out of physics?
Code:// Create the attachment:
var attachment = rope.gameObject.AddComponent<ObiParticleAttachment>();
attachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
attachment.target = bodyA.transform;
// Create a particle group and use it in the attachment:
var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
group.particleIndices.Add(particleIndex); // index of the particle in the rope
attachment.particleGroup = group;
You could also reuse the same particle group and just change the particle index: disable attachment, change particle index, re-enable attachment, in that order. This way you don't even have to allocate any memory at runtime, as you're reusing the same attachment/group.
There's another option too: note that dynamic attachments use pin constraints internally to couple particles and rigidbodies, so another option if you don't want to deal with groups/attachments is to create and manage your own pin constraints manually. Note this is a lower-level approach and considerably more complex. The manual contains information about how to create your own constraints at runtime: http://obi.virtualmethodstudio.com/manua...aints.html
There's also a "GrapplingHook" sample scene included that shows you how to create pin constraints at runtime, see Obi/Samples/RopeAndRod/SampleResources/Scripts/ExtendableGrapplingHook.cs
kind regards,
I'm also wondering how to exclude rope collisions with a player's capsule collider but not ignore collisions, e.g. with ground