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.
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. |
-
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.
-
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. -
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.
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
-
If required, adjust the
Axis
andSecondary 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. TheSecondary 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. -
Set the
Angular X Motion
property toLimited
orFree
. It’s likely you will also want to set the other axes toLocked
since these will not be considered by the Rotation Reader. -
Set the lower and upper limits for rotation, using the
Low Angular X Limit
andHigh Angular X Limit
properties on the Configurable Joint. These angular limits will correspond to a value of0
and1
respectively in theValue
property of the Rotation Reader.
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!