Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Changing solver gravity vector has no effect on particles
#1
I have a scene in Unity that uses Obi Fluid. The flow of the fluid can be controlled by rotating the Obi solver's gravity vector in response to WSAD (or the gyroscope input when running on a mobile device, which I haven't tested in the new version but which worked in the old). Note that changing the gravity vector is more convenient programmatically than rotating scene objects because it means I can more easily use a generic script. It also seems to be more stable than rotating geometry.

This all works fine when using `Obi Fluid v6.0.1 in Unity 2021.3.31`, but no longer works using `Obi Fluid 6.5.4 in Unity 2022.3.28`.

In the old version, I set the gravity vector in the `void Update()` method using




Code:
if (Input.GetKey(KeyCode.W))
{
    obiSolver.parameters.gravity = Quaternion.Euler(0, 0, zRotationRate * Time.deltaTime) * obiSolver.parameters.gravity;
}

obiSolver.PushSolverParameters();


(and three others for the other keys), and it works fine (I write the gravity vector to a textbox afterward) - the particles move in response to the changing direction of gravity.

However, in the new version this doesn't actually change the parameter at all. Weirdly, after some trial and error, I found I have to use a temporary `Vector3` variable and then set the parameter.





Code:
if (Input.GetKey(KeyCode.W))
{
    TempGravityVector = Quaternion.Euler(0, 0, zRotationRate * Time.deltaTime) * TempGravityVector;
}

obiSolver.parameters.gravity = TempGravityVector;
obiSolver.PushSolverParameters();


After setting `TempGravityVector = obiSolver.parameters.gravity;` in the `Start()` method, obviously). That does set the gravity parameter. However, it has no effect on the particles at all. The gravity vector does change but the particles don't seem to know it, and I'm flummoxed as to why. Anyone have any ideas?

PS I haven't tried other combinations of versions of Obi and Unity as that would seem to me to be a nightmare.
Reply
#2
Hi!

It is no longer necessary to access the internal parameters struct and push the parameters manually. Use solver.gravity directly, like this:

Code:
solver.gravity = myGravityVector;

Note you can also choose whether the gravity is expressed in local or world space, changing solver.gravitySpace. See the API docs for details.
Reply
#3
Ah, I knew it had to be something simple!

Thanks, I have it working now.
Reply