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.
- Listed in Global namespace: T to X
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
VelocityJoint() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
22 private and internal fields
| Member | What it is |
|---|---|
private Rigidbody connectedBody | The held pickup's rigidbody. |
private Vector3 gripPointPosition | The interaction point position this step, the unlimited target. |
private bool hasPull | True while a pull transform is set. |
private bool isLimitingPositionFromPickup | Whether the pickup asked for the target to be kept within arm's reach of the shoulder. |
private bool isPullHorizontalOnly | Whether the pull aim drops the component along the hand's up axis. |
private bool isRotating | Backing field for IsRotating. |
private bool isSwingable | Copied from Pickup.IsSwingable. Swingable items move the joint target instead of having their velocity set. |
private ConfigurableJoint joint | Backing field for Joint. |
private Quaternion lastGrabRotation | Hand rotation at grab time, so the item keeps the angle it was grabbed at relative to the hand. |
private Vector3 limitedPosition | The target position after limiting it to arm's reach. |
private static Logger logger | Logs failures while working out the pull rotation. |
private NetworkRigidbody networkRigidbody | The held body's NetworkRigidbody, turned off while held. |
private Quaternion offsetRotation | Backing field for OffsetRotation. |
private Pickup pickup | The held pickup. |
private float positionMultiplier | Backing field for PositionMultiplier. |
private AnimationCurve positionScaler | Backing field for PositionScaler. |
private Transform pull | Transform set by SetPull. |
private float rotationMultiplier | Backing field for RotationMultiplier. |
private AnimationCurve rotationScaler | Backing field for RotationScaler. |
private Transform shoulder | Shoulder transform from the hand's ArmController, used to limit reach. Null when the hand has no arm IK. |
private Vector3 shoulderPosition | Shoulder position this step, for reach limiting and gizmos. |
private VelocityPickupSettings velocityPickupSettings | The pickup type's settings. Its IsLimitingJointPosition must be on for reach limiting. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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. |