Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to simulate Obi Rope physics?
#1
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
Reply
#2
(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
Reply