> For the complete documentation index, see [llms.txt](https://earnest-robot.gitbook.io/auto-hand-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://earnest-robot.gitbook.io/auto-hand-docs/auto-hand/extras/physics-gadgets/physics-gadget-lever.md).

# Physics Gadget Lever

This component Requires a [Hinge Joint](https://docs.unity3d.com/Manual/class-HingeJoint.html) and a [Rigidbody](https://docs.unity3d.com/ScriptReference/Rigidbody.html), the physical qualities of the lever will be set through these components.&#x20;

OnMax, OnMin Events based on hinge joint limits

<div align="left"><img src="/files/Tnd9NEll0P06YWwhwIko" alt=""></div>

#### `Invert`:   When set to true, the value returned by the gadget is inverted. This can be used to reverse the direction or effect of the gadget's movement.

#### `Play Range`: Defines the minimum absolute value required for the gadget to return a non-zero value. For instance, with a play range of 0.1, the gadget must be moved 10% of its range to yield a result. This setting helps in creating a dead zone where minor movements are ignored.

#### `Threshold`:  This variable, with a minimum value of 0.01, defines the percentage (0-1) from the required value needed to trigger the associated events. For example, if the threshold is set to 0.1, the `OnMax` event is called at a value of 0.9, `OnMin` at -0.9, and `OnMid` at -0.1 or 0.1.

#### `Step Count`:  Steps determine which sections the lever will stop on. 0 will not create steps and only use the joint settings. 2 lock a gadget on on/off only. 100 will stop the gadget where you release it

#### `Start Step`:  The step the lever should start on

**`On Max Event`: This event is triggered based on the configurable joints limits minus the threshold**

**`On Mid Event`: This event is triggered based on the configurable joints limits minus the play**

**`On Min Event`: This event is triggered based on the configurable joints limits minus the threshold**

**`Step Events`:** An array of `StepEvent` structures, each containing events for entering and exiting specific steps.

### How to Use Step Events

1. **Define the Steps:** First, decide how many discrete positions (steps) your lever should have. This is set by the `stepCount` variable in the `PhysicsGadgetLever` script. For instance, if you want your lever to have 3 distinct positions, you would set `stepCount` to 3.
2. **Add Step Events to Array:** The `stepEvents` array holds the events for each step. You need to ensure that the size of this array matches your `stepCount`. Each element in this array represents a step and has two events: `OnStepEnter` and `OnStepExit`.
3. **Assigning Actions to Events:**
   * In the Unity Editor, you will see a list of steps under the `PhysicsGadgetLever` component.
   * For each step, you can assign actions to `OnStepEnter` and `OnStepExit`. These actions can be any function you want to be called - for example, playing a sound, changing a light's color, or triggering an animation.
   * To assign an action, click the '+' button under the event in the Inspector and drag a GameObject from your scene into the slot that appears. Then, select the function to call from the dropdown list.
