Obi Official Forum
Help How to simulate Obi Rope physics? - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help How to simulate Obi Rope physics? (/thread-4114.html)



How to simulate Obi Rope physics? - oleegarch - 21-02-2024

When i use in unity
Code:
Physics.Simulate(Time.fixedDeltaTime);
The Obi Rope is not simulated. Do I understand correctly that Obi Rope need to be simulated in a separate script? If it is true, how i can do this?

I'm developing a game where i need to detect in my server that user actually wins. My full code of simulation process:

Code:
private void Start() {
    Physics.simulationMode = SimulationMode.Script;
    Simulate();
}

private void Simulate() {
    GameObject machine = Instantiate(machinePrefab);
    MachineController controller = machine.GetComponent<MachineController>();
    APIMachineControlStateRequest request = JsonUtility.FromJson<APIMachineControlStateRequest>(json);
    controller.SetSimulate(Physics.defaultPhysicsScene);
    foreach(MachineControlState state in request.value) {
        controller.SetState(state);
        Physics.Simulate(Time.fixedDeltaTime);
    }
}
When i start it, Obi Rope behave unpredictably


RE: How to simulate Obi Rope physics? - josemendez - 22-02-2024

(21-02-2024, 06:09 PM)oleegarch Wrote: When i use in unity
Code:
Physics.Simulate(Time.fixedDeltaTime);
The Obi Rope is not simulated.

Physics.Simulate only ticks Unity's internal physics engine. It won't call FixedUpdate() for any scripts, or update other physics-related systems you may be using.

(21-02-2024, 06:09 PM)oleegarch Wrote:  Do I understand correctly that Obi Rope need to be simulated in a separate script? If it is true, how i can do this?

Correct, as it is a separate engine. Has nothing to do with Unity's built-in physics engine.

You do this by calling the ObiFixedUpdater's FixedUpdate() method manually, or even by writing your own ObiUpdater subclass that gets finer controller update cycle and physics state interpolation. See the API docs for ObiUpdater: http://obi.virtualmethodstudio.com/api.html