Change particle mass via script - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Change particle mass via script (/thread-546.html) |
Change particle mass via script - leonrdo - 20-04-2018 Using ObiRope 3.3, I'm trying to change the mass of a single particle via script following the tutorial http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html but its not working the way I think is supposed to work. For example, calling this code, after a key is pressed, Code: float[] mass = new float[1]; its not keeping the second particle fixed, as I supposed it would make. Did I miss anything? Thanks in advance RE: Change particle mass via script - josemendez - 21-04-2018 (20-04-2018, 08:15 PM)leonrdo Wrote: Using ObiRope 3.3, I'm trying to change the mass of a single particle via script following the tutorial http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html This does fix the particle for me. However, if the particle had non-zero velocity prior to being fixed, it will keep that velocity (but collisions or constraints will not be able to change it). So you should usually pair this with a call to Oni.SetParticleVelocities() to set its velocity to zero, and optionally also set its position. cheers, RE: Change particle mass via script - leonrdo - 24-04-2018 Thanks again Jose Setting the velocity before the mass did solve my problem, but running in Editor Mode, when I click Edit Particles to check the particle's properties, the mass changes back to default value. Not that this is crucial, once executing the Standalone of my project, the particles remains fixed. (21-04-2018, 07:57 AM)josemendez Wrote: This does fix the particle for me. However, if the particle had non-zero velocity prior to being fixed, it will keep that velocity (but collisions or constraints will not be able to change it). So you should usually pair this with a call to Oni.SetParticleVelocities() to set its velocity to zero, and optionally also set its position. RE: Change particle mass via script - josemendez - 25-04-2018 (24-04-2018, 07:33 PM)leonrdo Wrote: Thanks again Jose The editor stores per-particle masses (1/inverse mass) to prevent precision loss from switching from mass to inverse mass back and forth, since it must present the user a mass value in the interface and convert whenever there's a change. This means that if you only update the inverse mass trough code but do not update the editor's mass, it will re-set the particle inverse mass to 1/mass every time you select the particle. As you discovered, this only happens in the editor and it is not an issue when altering masses at runtime. cheers! |