Skip to main content

BowString

A class in Root.Township, the global namespace.

The grabbable string of a bow. Pulling it moves the string within limits, drives the bow's draw animation and haptics, and an arrow docked in it is shot on release.

Constructors​

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

Fields​

30 private and internal fields
MemberWhat it is
private AltaCoroutine activeCoroutineThe running SpringCoroutine, stopped when the string is grabbed again.
private Animator animatorAnimator with the "Draw" state that bends the bow. Only on while the string is used.
private HandGestureDefinition arrowPullGestureHand gesture used while pulling the string.
private LineRenderer bottomStringLine renderer for the lower half of the string.
private Transform bottomTargetPoint the lower string line runs to.
private Bow bowBacking field for Bow, the bow this string belongs to.
private AnimationCurve bowHandHapticHaptic curve played on the bow hand on release, scaled by strength.
private Transform cachedTransformCached transform of the string.
private float currentZCurrent local pull depth of the string.
private PickupDock dockBacking field for StringDock, where the arrow is knocked.
private float dropDistanceSquaredSquared distance between hand and string at which a local player drops the string.
private ExtraArrowUpdater extraArrowUpdaterBacking field for ExtraArrowUpdater.
private float hapticHaptic strength while pulling, scaled by draw strength (0.25 by default).
private Interactor interactorHoldingBowStringInteractor pulling the string, used for haptics and the drop distance check.
private bool isAimOnlyHorizontalPassed to the bow's joints so aiming only turns horizontally.
private static Logger loggerNLog logger. Warns when the bow has no physical material.
private Pickup pickupBacking field for Pickup, the string's own pickup.
private AnimationCurve pullbackSpeedCurve for how fast the string can be pulled back at each draw depth.
private Shooter shooterShooter that fires the docked arrow.
private RTPC shootStrengthRTPCWwise parameter set to the shot strength for the release sound.
private AnimationCurve springCurve for the string springing back after release. Its last key sets the duration.
private AnimationCurve strengthCurveCurve from pull depth (rest to zMin) to shot strength.
private bool stringBtnInspector button that runs UpdateStringRenderers.
private MethodSyncStruct<ShootArguments> syncShootMethod sync field. Never set or used in this build.
private float tightnessMultiplierBacking field for TightnessMultiplier. -1 means not worked out yet.
private LineRenderer topStringLine renderer for the upper half of the string.
private Transform topTargetPoint the upper string line runs to.
private float zIdealLocal z position of the string at rest, read in Awake.
private float zMaxClosest local z the string can sit at.
private float zMinFurthest local z the string can be pulled to (full draw).

Properties​

MemberWhat it is
Bow Bow { get; }The bow this string belongs to.
ExtraArrowUpdater ExtraArrowUpdater { get; }Component that handles extra arrows shot along with the main one.
bool IsIgnoringCollisionOnShoot { get; set; }If true, a shot arrow briefly ignores collisions with the bow and the shooter's body.
Pickup Pickup { get; }The string's own pickup that the hand grabs.
PickupDock StringDock { get; }The dock an arrow is knocked into.
1 private and internal property
MemberWhat it is
private float TightnessMultiplier { get; }Bow tightness from its physical material (tightness times bow impact), or 1 if none. Cached after the first read.

Events​

MemberWhat it is
event Action<BowString, NetworkEntity, Vector3> OnShootingEntityRaised when an arrow entity is shot, with the string, the arrow and a vector from the shooter.
event Action<float> OnUpdatedStringPullRaised with the draw strength each time the string moves.

Methods​

MemberWhat it is
override void Initialize()Hooks grab, release, dock and bow pickup events.
22 private and internal methods
MemberWhat it is
private void ArrowKnocked(Interactor interactor, Pickup pickup, PickupDock dock)When an arrow docks on the string, moves a local player's grab to the string and plays the knock sound if the bow is held.
private void Awake()Stores the rest position, sets the string pickup's parent and hooks the shooter's pre-shoot and shoot events.
private void BowDocked(Interactor interactor, Pickup bowPickup, PickupDock dock)When the bow is docked, scales the string lines if needed and snaps the string back to rest.
private void BowUndocked(Interactor interactor, Pickup arg2, PickupDock arg3)Resets the string line thickness when the bow leaves a dock.
private void Destroyed(NetworkEntity entity, bool isUnload)Releases the string properly if it's held when the entity is destroyed.
private void ForceDrop(Interactable arg1, Interactor arg2)Drops the string when the bow itself is let go.
private void FreezeAnimator()Sets the "Draw" animation to its start and turns the animator off.
private float GetStrength()Draw strength (0 to 1) from the strength curve for how far the string is pulled.
private float GetStrength(float z)Draw strength (0 to 1) from the strength curve for how far the string is pulled.
private void HeldUpdate()Each IK update while held: moves the string toward the hand, slowed by bow tightness, then updates haptics, visuals and arrow aim.
private void IgnoreArrowCollisions(Shooter arg1, Pickup arrow)Before a shot, stops the arrow colliding with the bow and the shooting player for a while.
private void IgnoreCollisionBetweenArrowAndBow(Pickup pickup, PlayerCharacter player)Ignores collisions between the arrow and the bow plus player body colliders for a set time.
private void InteractFilter(Interactor interactor, Interactable interactable, ref bool result)Only allows grabbing the string or docking an arrow while someone holds the bow.
private void OnShoot(Shooter arg1, Pickup arg2, Vector3 arg3)Raises OnShootingEntity with the arrow entity and its velocity.
private IEnumerable<Collider> PlayerAndBowColliders(PlayerCharacter player) (iterator)Yields the bow's colliders and the player's body colliders.
private void PreBowDocked(Interactor interactor, Pickup bowPickup, PickupDock dock)Before the bow docks, undocks any arrow, resets the string visuals and freezes the animator next frame.
private IEnumerator SpringCoroutine() (iterator)Animates the string springing back to rest after release, along the spring curve.
private void StringGrabbed(Interactable pickup, Interactor interactor)On grab: turns the animator on, sets the pull gesture, starts HeldUpdate and points the bow joints at the pulling hand.
private void StringReleased(Interactable arg1, Interactor interactor)On release: springs the string back, plays sound and haptics, and if the local player held it with an arrow, shoots.
private void UpdateArrowRotation()Points the docked arrow at the bow's hand rest for whichever hand holds the bow.
private void UpdateLineRenderersThickness(float thickness)Sets the width of both string lines.
private void UpdateStringRenderers(bool preDock = false)Client: sets the draw animation to the current strength and stretches the string lines to their targets.

Used in​

Members of other types that take, return or hold a BowString: