Immerse SDK
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Rotation Reader

The Rotation Reader component helps to facilitate various interactions that are based on rotating an object around a joint. It is suited for things like crank wheels, levers, and dials as demonstrated in the included prefabs.

Using a Rotation Reader, the arc of travel of an object affixed to a joint can be simplified to a 0-1 scaled value. This value can be read back as the object is moved around physically, or it can be set, moving the object into place. This may avoid a lot of complexity when, for example, determining if a valve is “open” or “closed” based on some rotation of a crank wheel across some set of predefined limits.

A Rotation Reader does not apply any physical forces - it relies on the attached Handles, Rigidbody and a Configurable Joint to limit it’s movement.

Rotation Reader component

Field Description
Value The 0-1 value that represents how much the joint’s attached rigidbody has rotated across the limits of the joint.

This can be set, moving the connected body into a position/rotation, but will also update automatically as the connected body moves due to physics.
Handles An array of Handles that should be attached to the connected body of the joint.
Toggle is Kinematic If this is set to true, the connected body will be set to kinematic when none of the handles are engaged. This will eliminate any “inertia” from the RigidBody when it is released.
On Value Changed This event is fired whenever Value changes.

Setting up the Rotation Reader

  1. Add a Rotation Reader component to the GameObject that will serve as the joint origin. A Rigidbody and a Configurable Joint component will be added automatically if not present already.

  2. Add a Rigidbody to a second GameObject which will be attached to the joint. Link this Rigidbody component to the Connected Body property of the Configurable Joint.

  3. If the connected body should be moved using XR, add the required Handle components to it and then add these to the Handles array of the Rotation Reader.

Setting up the Configurable Joint

This section mainly focuses on how the Configurable Joint interacts with the Rotation Reader.

A more detailed guide on how to use Configurable Joints can be found at its Unity Manual page and its associated API documentation

  1. If required, adjust the Axis and Secondary Axis properties of the Configurable Joint. This axis is in local space of the joint’s transform, and will be used as the the “X” axis when setting up limits. It is also used by the Rotation Reader to read and write to its Value property. The Secondary Axis will represent the Y axis, which is used to offset the position away from the joint. Given this, it’s recommended for these two axes to be orthogonal.

  2. Set the Angular X Motion property to Limited or Free. It’s likely you will also want to set the other axes to Locked since these will not be considered by the Rotation Reader.

  3. Set the lower and upper limits for rotation, using the Low Angular X Limit and High Angular X Limit properties on the Configurable Joint. These angular limits will correspond to a value of 0 and 1 respectively in the Value property of the Rotation Reader.

An example Configurable Joint that will restrict the rotation of the connected body between -45 and 45 degrees over the joint&rsquo;s local Y axis. Note that the <code>Axis</code> field specifies the axis used for the X axis limits.

Connected Body Orientation

The local Y axis of the connected Rigidbody is assumed to match the Configurable Joint’s Axis field. Bear this in mind when orienting any child objects to the connected body (e.g meshes) to ensure they look correct when rotated by the Rotation Reader.

The example Configurable Joint above is from the “Lever” example, which can be found in the Prefabs folder of the Interaction package.

Try experimenting with this and the other example prefabs to see how they work!