Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Predict the future.
#1
I'm probably hoping for the impossible, but....  

Is there any way I can predict where a ropes particle will be in the future? Say 1-3 seconds?
Reply
#2
(05-02-2023, 06:51 PM)idmah Wrote: I'm probably hoping for the impossible, but....  

Is there any way I can predict where a ropes particle will be in the future? Say 1-3 seconds?

Hi!

This can be done the same way as in any physics engine: store simulation state, advance the simulation any amount of time you need, reset simulation state.

Physics engines usually have a Simulate(), Step() or Advance() method (name varies between engines) that takes a delta time as parameter and will advance the simulation by that much time. You can't use large time deltas since trajectories are assumed the be linear for a single step, instead you typically advance the simulation in small increments until enough time has been simulated. So you'd do something like this (pseudocode):

Code:
time = 0;
predictionTime = 3;
stepSize = 0.02;

simulation.Store();

while (time < predictionTime)
{
simulation.Step(stepSize);
time += stepSize;
}

simulation.Restore();

First you store simulation state (body positions and velocities). Then you simply advance the simulation by taking small steps until 1-3 seconds have passed. Once you're done, you just reset the simulation state to what it was before.

Depending on your exact use case doing this can be fairly simple or really complex. If you only need to predict particle movement and there is no new particles being generated or particles being destroyed, no rigidbodies, colliders, or other gameplay objects involved, all you need to do is write your own ObiUpdater component that advances the solver's simulation manually (see ObiUpdater in the API docs, also see the included ObiUpdater derived components for reference). Simulation state can be stored using ObiActor.SaveStateToBlueprint() and restored using ObiActor.ResetParticles();

Now, if rigidbodies are involved (for instance if you have a box hanging from a rope), then you need to advance both Unity's rigidbody simulation and Obi in sync. And if gameplay objects are involved (for instance, transforms controlled by the user) things become even more complex as you also need to predict player input to some degree.

kind regards,
Reply