27-05-2020, 10:47 AM
(This post was last modified: 27-05-2020, 10:50 AM by josemendez.)
(27-05-2020, 10:39 AM)arrnav96 Wrote: Thankyou! You've almost answered everything, just one last thing,
If I'm locking for example the bottom and top particle to lock the object, then cut the object (splitting to two softbodies), how do I lock one of them again in runtime? The bigger piece needs to stay hovering, while smaller one falls off so no locking required in that.
Also, at runtime, how would I group and lock particles without the editor? How would I know which particle I'm locking by code?
"Locking" a particle basically means setting its mass to infinite. Which is equivalent to setting its inverse mass to zero, Obi internally works with inverse masses to avoid dealing with nasty Inf/NaN values. Setting the velocity to zero is usually also needed, to keep the particle from moving if they already had some momentum.
The ObiParticleAttachment simply wraps this all up nicely for you: It finds all particles in a particle group, stores their old inverse mass, and sets both their inverse mass and velocity to zero. When the attachment is deactivated, it also takes care of resetting their inverse masses to whatever values they had. It also sets the position of the now "locked" particles to match the transform they're attached to.
Given that you're not working with pre-made particle groups defined in editor, I think it would be easier for you to deal with particles directly. You'll need to find which particles you want to lock by checking their position (or any other attribute that helps you identify them), then setting their inverse mass to zero. See:
http://obi.virtualmethodstudio.com/tutor...icles.html