Controlling the Simulation

Starting and Stopping the Simulation

The SimulationEngine script on the SimulationEngine prefab handles starting and stopping the simulation. In the inspector, there is an option named Start Simulating that determines whether the simulation should start immediately upon the game starting. If unchecked, the simulation will have to be started manually.

To toggle the simulation state, call ToggleSimulation on the SimulationEngine object. An example of this can be found on the button in the demo scene.

Toggle Simulation button setup
Toggle Simulation button setup

Controlling a Pump

A pump can be created from the HorizontalPump prefab.  There are two main parts to changing the acceleration added by the pump.  First is the Maximum Acceleration property on the HorizontalPump script.  Second is the SetActuation(float) function in the HorizontalPump script.  SetActuation takes a float between -1 and 1, multiplies it by the Maximum Acceleration, and sets that as the acceleration used in the flow calculations.  This means the range of possible accelerations will always be -Maximum Acceleration to Maximum Acceleration.

Maximum Acceleration property
Maximum Acceleration property

The simplest way to dynamically control the pump acceleration is using a Unity UI Slider.  The demo scene has an example of this.  Because the value is scaled, the slider should always have a Min Value of -1, and a Max Value of 1.  Then add SetActuation on the HorizontalPump object as the dynamic float function to call OnValueChanged.  Your slider should have values like below.

Slider setup for pump control
Slider setup for pump control
Be sure to choose the Dynamic float option
Be sure to choose the Dynamic float option