Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are fluid particles jumping around when simulating in local space?
#5
(06-08-2019, 10:57 AM)bobby Wrote: Hi there, it didn't work.

The particles are still jumping around. I changed the update mode to "After Fixed Update" and wrote a script to update the transform inside FixedUpdate:

    private void FixedUpdate()
    {

        if (Input.GetMouseButtonDown(0))
        {
            startMousePos = Input.mousePosition;
        }
        else if (Input.GetMouseButton(0))
        {
            var dir = (Input.mousePosition - startMousePos) / Screen.dpi / 10;

            transform.position += new Vector3(dir.x, 0, dir.y);
        }
    }


Interesting. I set the update mode to Late Update and it works now.

LateUpdate should not be used unless it is completely unavoidable, as it does not use a fixed timestep (although it tries to, by applying a low-pass filter on the render timestep) and so the results are highly unphysical. As a rule of thumb physics should always be updated in FixedUpdate. A better alternative would be to subscribe to the start of the solver's frame, and perform the movement there. Here's a sample script, that should be attached to the solver:

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class Mover : MonoBehaviour
{
   ObiSolver solver;
   public float speed = 1;

   void Awake()
   {
       solver = GetComponent<ObiSolver>();
       solver.OnFrameBegin += Move;
   }

    private void OnDestroy()
    {
       solver.OnFrameEnd -= Move;
    }

    void Move(object sender, EventArgs eventArgs)
   {
       transform.Translate(Vector3.left * Time.deltaTime * speed);
   }
}
Reply


Messages In This Thread
RE: Why are fluid particles jumping around when simulating in local space? - by josemendez - 08-08-2019, 08:35 AM