Immerse

Description

An interactable lever that uses physics to move and is synchronised between different users. Movement is restricted by the physics hinge component.

For an overview of how our SDK deals with interactions, please see Interaction Overview.

How It Works

Lever uses physics (a Rigidbody (Unity documentation) , HingeJoint (Unity documentation) and a Collider (Unity documentation) ) to enable interaction. To engage a lever, hold the controller close to the handle and push the VR controller trigger.

Once the lever is engaged, it sends a message to all users in a scene. TransformSync will ensure that all users in the scene can see the lever being moved (read more about Synchronisation).

Lever also supports reactions, which allows logic operations to be integrated, when the lever is moved and/or snapped.

How To Implement

  1. Select a new GameObject. This object will become the lever's base and will be the pivot it rotates around.
  • Reset the Position, Rotation and Scale of the Object. Ensure Position is set to <0, 0, 0>
  • Add Rigidbody component
  • Add HingeJoint component
    • Set the correct Axis for the lever. This is the axis around which the lever will rotate.
    • If the lever is restricted in rotation, check the Limits box and set the angles.
  • Add TransformSync component
    • Set the Sync Properties to Rotation only.
  • Add a new GameObject as a child and name it "Handle" (or something to identify it as the lever's handle)
  • Move this handle object to the correct location relative to the lever's base.
  • Add a collider (BoxCollider or CapsuleCollider is best)
  • Add a Lever component
    • Drag a reference from the lever's base into the TransformSync property of the Lever component. This ensures is aware of the lTransformSync is located.
  • Add a child object and a Mesh that will represent the handle to the new child.
  • Optionally add snap targets to TransformSync. For instance, if the lever can be open or closed, an open and close snap target can be added.

🚧

Common Issues

Ensure that the correct axis has been set on the HingeJoint and that it has been set up correctly. Also, watch out for colliders in the wrong place.

Options

The Lever component provides several properties that control its behaviour:

PropertyDescription
Verbose Logging Enabled
When enabled, this component instance will log verbosely to the console (only in the Editor). This is useful for debugging, but can have a detrimental effect on the framerate as verbose logging sometimes logs every frame.
IndexThe object's unique index - this will be automatically set by the SDK and should not be edited.
TransformSyncA reference to the TransformSync component for this Lever. If this is not set, the SDK will look for the TransformSync on the same GameObject.
Requires Two HandsIf enabled, the object will only allow interaction when two or more controllers are engaged with it.
Requires Two Hand For UnsnappingIf enabled, the object will only allow unsnapping when two or more controllers are engaged with it.
Is Kinematic After EngageRigidbody will be set to non-kinematic when engaged, but after engagement finished, will change to kinematic.
Interaction RequirementsA set of requirements that need to be met to allow interaction; can be used to disable the object until a particular state is reached.
SensitivityControls how "fast" the lever moves. Sometimes a heavy lever should move slowly to feel better.
Interaction PointAn alternative point to use for movement calculations when interacting with the object.

📘

Immerse SDK Class Library

ImmerseSDK.Interaction.Lever class
ImmerseSDK.Interaction.SnapTarget class

Unity Editor Component

Unity iconTry out this component in the Examples project

Examples (menu) > Interactions > Load Lever Example

Learn more about the Examples project

Updated 4 months ago


Lever


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.