Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I translate all the particles' position by a certain vector?
#1
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?
Reply
#2
(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/tutor...icles.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;
}
Reply
#3
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);
            }
        }
   }
Reply