Skip to main content

VelocityJoint

A class in Root.Township, the global namespace.

Hold joint for velocity-driven pickups. PickupJoints adds it to the interactor's interaction point, and each physics step it sets the held body's velocity and angular velocity toward the hand.

Constructors​

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

Fields​

22 private and internal fields
MemberWhat it is
private Rigidbody connectedBodyThe held pickup's rigidbody.
private Vector3 gripPointPositionThe interaction point position this step, the unlimited target.
private bool hasPullTrue while a pull transform is set.
private bool isLimitingPositionFromPickupWhether the pickup asked for the target to be kept within arm's reach of the shoulder.
private bool isPullHorizontalOnlyWhether the pull aim drops the component along the hand's up axis.
private bool isRotatingBacking field for IsRotating.
private bool isSwingableCopied from Pickup.IsSwingable. Swingable items move the joint target instead of having their velocity set.
private ConfigurableJoint jointBacking field for Joint.
private Quaternion lastGrabRotationHand rotation at grab time, so the item keeps the angle it was grabbed at relative to the hand.
private Vector3 limitedPositionThe target position after limiting it to arm's reach.
private static Logger loggerLogs failures while working out the pull rotation.
private NetworkRigidbody networkRigidbodyThe held body's NetworkRigidbody, turned off while held.
private Quaternion offsetRotationBacking field for OffsetRotation.
private Pickup pickupThe held pickup.
private float positionMultiplierBacking field for PositionMultiplier.
private AnimationCurve positionScalerBacking field for PositionScaler.
private Transform pullTransform set by SetPull.
private float rotationMultiplierBacking field for RotationMultiplier.
private AnimationCurve rotationScalerBacking field for RotationScaler.
private Transform shoulderShoulder transform from the hand's ArmController, used to limit reach. Null when the hand has no arm IK.
private Vector3 shoulderPositionShoulder position this step, for reach limiting and gizmos.
private VelocityPickupSettings velocityPickupSettingsThe pickup type's settings. Its IsLimitingJointPosition must be on for reach limiting.

Properties​

MemberWhat it is
Controller Controller { get; private set; }The controller of the hand holding the pickup, set in Initialize.
Interactor Interactor { get; private set; }The interactor (hand) holding the pickup.
bool IsRotating { get; set; }When false, the item is only pulled to the hand's position and its rotation isn't driven.
Joint Joint { get; }The ConfigurableJoint added in Initialize, or null after release.
Quaternion OffsetRotation { get; set; }A stored rotation offset. This class's own code never reads it.
float PositionMultiplier { get; set; }Scales the velocity that pulls the item toward the hand.
AnimationCurve PositionScaler { get; set; }Curve over distance to the target that scales the pull velocity.
float RotationMultiplier { get; set; }Scales the angular velocity that turns the item toward the hand's rotation.
AnimationCurve RotationScaler { get; set; }Curve over the remaining angle (0 to 1 for 0 to 180 degrees) that scales the turn speed.

Methods​

MemberWhat it is
void Initialize(Pickup pickup, Interactor interactor, Rigidbody connectedBody, bool isLimitingPosition, VelocityPickupSettings velocityPickupSettings, Quaternion lastGrabRotation)Starts the hold: adds a ConfigurableJoint, connects the pickup's body, turns off its NetworkRigidbody and hooks InteractionEnded.
void SetPull(Transform transform, bool isHorizontalOnly)Makes the held item point away from the given transform, optionally only horizontally. BowString uses it for the drawing hand; null clears it.
3 private and internal methods
MemberWhat it is
private void FixedUpdate()While held, sets the body's velocity and spin toward the grip point (limited to arm's reach), or moves the joint target for swingable items.
private void OnDrawGizmos()Editor gizmos for the shoulder, grip point and arm-limited target.
private void PickupInteractionEnded(Interactable interactable, Interactor interactor)When this hand lets go, turns the NetworkRigidbody back on (unless docked or still held), restores max angular velocity and destroys the joint.