Skip to main content

NonJointLever

A class in Root.Township, the global namespace.

A lever that follows the hands on its handle by rotating a target, with no physics joint. Not networked; each machine runs it from the hands it sees and fires on and off events locally.

Constructors​

MemberWhat it is
NonJointLever()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

18 private and internal fields
MemberWhat it is
private Quaternion centerMiddle of the allowed rotation range.
private Pickup handlePickupThe pickup players grab to move the lever.
private bool isActiveTrue while the lever is in its active angle range.
private float maxActiveAngleUpper angle of the active range.
private float maxAngleUpper limit of the rotation.
private float maxRangeHalf the rotation range, worked out in Awake.
private float minActiveAngleLower angle of the active range.
private float minAngleLower limit of the rotation.
private float minInactiveAngleOnce active, the angle must fall below this before it counts as off again.
private Vector3 neutralPositionLocal direction that counts as zero rotation.
private Transform pivotTransform the grip point is measured from.
private float returnSpeedHow fast it swings back to rest when let go. Zero leaves it where it is.
private Vector3 rotationAxisLocal axis the lever turns around.
private Transform targetTransform that is rotated.
private float targetRotationStarting angle of target.
private UnityEvent turnedOffEvent raised when the lever leaves the active range.
private UnityEvent turnedOnEvent raised when the lever enters the active range.
private IUnityUpdateMethod updatePositionPer-frame update registration.

Methods​

4 private and internal methods
MemberWhat it is
private void Awake()Hooks the handle's grab, sets the starting rotation and works out the allowed range.
private void OnDestroy()Stops the update.
private void StartedInteracting(Interactable arg1, Interactor arg2)Starts the per-frame update when the handle is grabbed.
private void UpdatePosition()Rotates toward the average grip point within range, or back to rest by returnSpeed, and fires turnedOn or turnedOff as the angle crosses the thresholds.