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.
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.
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 Bodyproperty 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
Handlesarray of the Rotation Reader.
This section mainly focuses on how the Configurable Joint interacts with the Rotation Reader.
If required, adjust the
Secondary Axisproperties 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 Axiswill 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.
Angular X Motionproperty to
Free. It's likely you will also want to set the other axes to
Lockedsince these will not be considered by the Rotation Reader.
Set the lower and upper limits for rotation, using the
Low Angular X Limitand
High Angular X Limitproperties on the Configurable Joint. These angular limits will correspond to a value of
1respectively in the
Valueproperty 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
Prefabsfolder of the Interaction package.
Try experimenting with this and the other example prefabs to see how they work!
Updated 6 months ago