Obi Official Forum
Can I translate all the particles' position by a certain vector? - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Can I translate all the particles' position by a certain vector? (/thread-2475.html)



Can I translate all the particles' position by a certain vector? - emz06 - 07-09-2020

Hi,

-I have fluid particles (shampoo-type of liquid) resting on a platform.

-Suddenly this platform shifts downward, and to the side.

But the problem is the particles can't keep up with the high speed of the platform.
I tried to increase the friction, but it did not help.

Is it possible to loop through all the particles and, on every frame, translate their position by the same amount as the platform movement?


RE: Can I translate all the particles' position by a certain vector? - josemendez - 07-09-2020

(07-09-2020, 11:36 AM)emz06 Wrote: Hi,

-I have fluid particles (shampoo-type of liquid) resting on a platform.

-Suddenly this platform shifts downward, and to the side.

But the problem is the particles can't keep up with the high speed of the platform.
I tried to increase the friction, but it did not help.

Is it possible to loop through all the particles and, on every frame, translate their position by the same amount as the platform movement?

Yes, you can. Make sure to also translate their previousPosition, as this is PBD (and velocities are calculated as (position - prevPosition) / dt). If you only change their current position, they will gain a lot of velocity.

See:
http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html

Example:
Code:
for (int i = 0; i < actor.solverIndices.Length; ++i){

     // retrieve the particle index in the solver:
     int solverIndex = actor.solverIndices[i];


     actor.solver.positions[solverIndex] += translation;
     actor.solver.prevPositions[solverIndex] += translation;
}



RE: Can I translate all the particles' position by a certain vector? - emz06 - 11-09-2020

Hi,

Thanks for that. I tried to make a coroutine for that, but I don't understand some of the structures involved, as well as the presence of a Vector4 as the translation.
Please see my code below. Note: the platform is moved by IK, so the movement happens at the end of the frame.
What did I do wrong there?

Code:
public IEnumerator ParticlesFollowPlatform_IE()
    {
        float duration = 3;
        float i = 0;

        Vector3 translation = platform.position - platformLastPosition;
        platformLastPosition = platform.position;

        while (i < duration)
        {
            yield return new WaitForEndOfFrame();

            i += Time.deltaTime;

            Vector3 translation = platform.position - platformLastPosition;
            platformLastPosition = platform.position;

            for (int x = 0; x < myActor.solverIndices.Length; x++)
            {
                int solverIndex = myActor.solverIndices[x];

                myActor.solver.positions[solverIndex] += new Vector4 (translation.x, translation.y, translation.z, 0) ;
                myActor.solver.prevPositions[solverIndex] += new Vector4(translation.x, translation.y, translation.z, 0);
            }
        }
   }