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.
- Listed in Global namespace: A to B
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
BowString() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
30 private and internal fields
| Member | What it is |
|---|---|
private AltaCoroutine activeCoroutine | The running SpringCoroutine, stopped when the string is grabbed again. |
private Animator animator | Animator with the "Draw" state that bends the bow. Only on while the string is used. |
private HandGestureDefinition arrowPullGesture | Hand gesture used while pulling the string. |
private LineRenderer bottomString | Line renderer for the lower half of the string. |
private Transform bottomTarget | Point the lower string line runs to. |
private Bow bow | Backing field for Bow, the bow this string belongs to. |
private AnimationCurve bowHandHaptic | Haptic curve played on the bow hand on release, scaled by strength. |
private Transform cachedTransform | Cached transform of the string. |
private float currentZ | Current local pull depth of the string. |
private PickupDock dock | Backing field for StringDock, where the arrow is knocked. |
private float dropDistanceSquared | Squared distance between hand and string at which a local player drops the string. |
private ExtraArrowUpdater extraArrowUpdater | Backing field for ExtraArrowUpdater. |
private float haptic | Haptic strength while pulling, scaled by draw strength (0.25 by default). |
private Interactor interactorHoldingBowString | Interactor pulling the string, used for haptics and the drop distance check. |
private bool isAimOnlyHorizontal | Passed to the bow's joints so aiming only turns horizontally. |
private static Logger logger | NLog logger. Warns when the bow has no physical material. |
private Pickup pickup | Backing field for Pickup, the string's own pickup. |
private AnimationCurve pullbackSpeed | Curve for how fast the string can be pulled back at each draw depth. |
private Shooter shooter | Shooter that fires the docked arrow. |
private RTPC shootStrengthRTPC | Wwise parameter set to the shot strength for the release sound. |
private AnimationCurve spring | Curve for the string springing back after release. Its last key sets the duration. |
private AnimationCurve strengthCurve | Curve from pull depth (rest to zMin) to shot strength. |
private bool stringBtn | Inspector button that runs UpdateStringRenderers. |
private MethodSyncStruct<ShootArguments> syncShoot | Method sync field. Never set or used in this build. |
private float tightnessMultiplier | Backing field for TightnessMultiplier. -1 means not worked out yet. |
private LineRenderer topString | Line renderer for the upper half of the string. |
private Transform topTarget | Point the upper string line runs to. |
private float zIdeal | Local z position of the string at rest, read in Awake. |
private float zMax | Closest local z the string can sit at. |
private float zMin | Furthest local z the string can be pulled to (full draw). |
Properties
| Member | What 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
Events
| Member | What it is |
|---|---|
event Action<BowString, NetworkEntity, Vector3> OnShootingEntity | Raised when an arrow entity is shot, with the string, the arrow and a vector from the shooter. |
event Action<float> OnUpdatedStringPull | Raised with the draw strength each time the string moves. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Hooks grab, release, dock and bow pickup events. |
22 private and internal methods
| Member | What 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:
BowDrawSkill.bowStrings, BowDrawSkill.HandleInputChanged, BowDrawSkill.inputs, BowDrawSkill.OnArrowShot, BowMultiArrowShot.bowStrings, BowMultiArrowShot.CreateExtraArrows, BowMultiArrowShot.inputs, BowMultiArrowShot.OnArrowShot, LightBeamSkill.DestroyShotArrow, LightBeamSkill.HandleInputChanged, BowStringPullbackInputMethod.bowString, ExtraArrowUpdater.bowString, ExtraArrowUpdater.ShootExtraArrows.