Skip to main content

Arrow

A class in Root.Township, the global namespace.

An arrow item's flight: aligns it with its velocity while flying and, with the newer precision mode, applies seeded deviation from ArrowFlightSettings that the server syncs so every side flies the same path.

Constructors​

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

Fields​

20 private and internal fields
MemberWhat it is
private IUnityUpdateMethod arrowFlightHandle of the registered flight update.
private ArrowFlightSettings arrowSettingsBacking field for ArrowSettings; flight curves used when useNewPrecision is on.
private NetworkEntity arrowTipBacking field for ArrowTip.
private float basePrecisionDevianceMax random angle in degrees added to a shot when useNewPrecision is off.
private Rigidbody cachedRigidbodyBacking field for Rigidbody.
private JointSlot[] craftedPartsJoint slots for the crafted parts. Not read in this class.
private Embeddable embeddableThe arrow's Embeddable; embedding stops the flight.
private float flightSpeedLaunch speed used by the complex flight.
private float flightTimeSeconds since the complex flight started.
private ImpactTool impactToolBacking field for ImpactTool.
private static Logger loggerNLog logger for this class.
private float materialWeightModifierWeight factor from the arrow's weight and material tightness, passed to the flight settings.
private float maxExtraExtra weight factor per unit of weight added to materialWeightModifier. Defaults to 0.1.
private float minSquareVelocityForAligningSquared speed above which the arrow is turned to face its velocity. Defaults to 10.
private ArrowEvent onShotOnServerEvent behind ShotOnServer, invoked on the server when the arrow is shot.
private PhysicalMaterialPart physicalMaterialMaterial part whose tightness multiplier affects materialWeightModifier.
private int randomSeedSeed for the editor gizmo preview only. Flight seeds come from the shot.
private Random.State randomStateThe arrow's own random state, so the server and clients deviate the same way.
private MethodSyncStruct<Arrow.ArrowFlightSync> syncFlightSync that sends flight speed and seed from the server to clients.
private bool useNewPrecisionWhen on, flight uses arrowSettings and a synced seed. When off, a simple random angle at launch.

Properties​

MemberWhat it is
ArrowFlightSettings ArrowSettings { get; set; }Flight settings used by the newer precision mode.
NetworkEntity ArrowTip { get; }The entity at the arrow's tip. Defaults to the arrow itself.
float FinalWeight { get; }The pickup's total weight, or 0.1 if there is no pickup.
List<ArrowFlightSettingsModifier> FlightModifiers { get; }Extra modifiers applied to the flight settings each step.
bool HasBeenShot { get; private set; }True from being shot until the flight stops.
ImpactTool ImpactTool { get; }The arrow's ImpactTool.
bool IsInFlight { get; private set; }True while the flight update is running.
Rigidbody Rigidbody { get; }The arrow's rigidbody.

Events​

MemberWhat it is
event Action<Arrow> ShotOnServerRaised on the server when the arrow is shot.

Methods​

MemberWhat it is
override void Initialize()Hooks destruction and sets up the flight sync message.
Vector3 Shoot(Vector3 baseDirection, float strength, bool isApplyingDeviation)Fires the arrow along a direction with a strength, or with a velocity. The older mode can add random spread.
void Shoot(Vector3 velocity)Fires the arrow along a direction with a strength, or with a velocity. The older mode can add random spread.
void ShootArrowWithVelocity(Vector3 velocity)Sets the velocity and starts the flight. Server: raises ShotOnServer.
void StartHandlingArrowDeviance(float speed, int randomSeed = -1)Starts the seeded deviation flight at a speed. Server: syncs the speed and seed to clients.
void StartSimpleArrowFlight()Starts the plain flight that only aligns the arrow with its velocity.
void StopUpdatingArrowFlight()Stops the flight update and clears HasBeenShot. Called on hit, embed or destroy.
13 private and internal methods
MemberWhat it is
private void AlignWithFlightDirection()Turns the rigidbody to face along its velocity.
private void Awake()Hooks StopArrowFlight to the embeddable's Embedded event.
private void ComplexArrowFlight()Fixed update for new-precision flight: sets velocity from arrowSettings with the arrow's own random state, then aligns it.
private void DestroyByScene(NetworkEntity entity, bool isUnload)Stops the flight update when the entity is destroyed by the scene.
private bool EnsureArrowTip()Inspector helper: sets arrowTip to this entity if it is empty.
private void Alta.Impact.IToolHitDependant.OnCollided(Collision collision, bool isHitting, ImpactTool tool)Stops the flight update when the arrow collides with something.
private void OnDestroy()Stops the flight update.
private void OnDrawGizmosSelected()Editor: draws the flight path preview from arrowSettings using randomSeed.
private void Alta.Impact.IToolHitDependant.OnHit(ImpactHitWithTool hit, ImpactTool tool)Stops the flight update when the arrow's tool hit lands.
private void SimpleArrowFlight()Fixed update for old-style flight: only aligns the arrow with its velocity when fast enough.
private void StartArrowFlight(Action method)Registers the given fixed-update flight method, marks the arrow in flight and turns on continuous collision.
private void StopArrowFlight(Embeddable embeddable)Stops the flight update when the arrow embeds.
private void SyncFlight(IPlayer player, Stream stream, Arrow.ArrowFlightSync arguments)Network handler for flight speed and seed. Clients start the same deviating flight the server did.

Used in​

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