06-01-2021, 09:14 AM
(06-01-2021, 08:18 AM)josemendez Wrote: This is what's happening in your script:
When you emit a new particle, you store its buoyancy value in userData.
When a particle hits a collider, you set its userData to 0.
(when particles are simulated by Obi, the contents of userData are diffused)
But you never do solver.buoyancies[k] = something. So ofc, buoyancy values are never actually set to the diffused values in userData.
In the Raclette sample scene, you'll see there's a "ColorFromViscosity" component added to the emitter. In its LateUpdate() method, color is driven by viscosity, then viscosity and surface tension are set to whatever values are in userData[k][0] and userData[k][1]. That's what maps the userData values to viscosity and surface tension and that's precisely what you're missing.
To make it clear, these are the steps required:
- buoyancy ---> userData (every time a particle is emitted)
- userData undergoes diffusion (during simulation, done automatically)
- userData ----> buoyancy (after simulation) // you're missing this one.
Anytime after the simulation has taken place (that is, after FixedUpdate()), you need to copy back from userData to buoyancies. LateUpdate() is a good place.
I added this code to my script and it works correctly
Code:
void LateUpdate()
{
for (int i = 0; i < emitter.solverIndices.Length; ++i)
{
int k = emitter.solverIndices[i];
emitter.solver.buoyancies[k] = emitter.solver.userData[k][0];
}
}
Thank you so much!