Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Custom ObiUpdater
#1
Pregunta 
Hi,

I'm trying to create a custom class that inherits from ObiUpdater that can simulate in one frame.

So far I have this class which I based on the code for ObiFixedUpdater:

Code:
public class PatchUpdater : ObiUpdater
{
    public void UpdateCloth(float delta, int substeps)
    {
        ObiProfiler.EnableProfiler();
       
        float substepDelta = delta / substeps;

        BeginStep(delta);

        for (int i = 0; i < substeps; ++i)
        {
            Substep(substepDelta);
        }
       
        EndStep(substepDelta);
       
        ObiProfiler.DisableProfiler();
    }
}

I've added the solver to the list of solvers in the inspector, and the simulation works using the ObiFixedUpdater component.

I would expect that given the parameters (3, 10) after calling the function the cloth's appearance would reflect 3 seconds worth of simulating. However, this doesn't appear to simulate the cloth at all.

What am I missing? Please let me know if I should provide any further information.

Cheers,
Jordan
Reply
#2
Hi Jordan,

You're not calling Interpolate() anywhere. This function updates rendering by interpolating the previous and current physics states. Since there's no call to Interpolate(), rendering is not updated at all.

Interpolate() should generally be called at the end of all physics steps in the frame. If you intend to have a single UpdateCloth() call that does everything, then call Interpolate() right after EndStep(). See ObiFixedUpdater or ObiLateUpdater for reference.

Note that passing (3, 10) to your function would result in an effective timestep of 0.3 seconds, which imho is way too much and will result in really inaccurate simulation. A typical timestep in a realtime physics engine would be 0.02 (Unity's default, btw). Remember that shorter timestep = better accuracy.
Reply