Skip to main content

Shooter

A class in Root.Township, the global namespace.

Launches a pickup (an arrow or any item) from a bow or similar launcher and syncs the shot. Both sides: the shooting client simulates and sends it, the server relays it to the chunk.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private float defaultDeviationMaximum random angle in degrees added to non-arrow shots fired locally.
private static Logger loggerLogger for this class.
private float maxExtraExtra velocity factor for arrows, scaled by the string tightness.
private float maxVelocityLaunch speed at full strength, before weight and material adjustments.
private PhysicalMaterialPart physicalMaterialOptional material of the bow string; gives tightness, minimum projectile weight and the velocity multiplier for light items.
private Pickup pickupThe launcher itself; only used to copy its last interactor onto the launched item.
private RTPC shootStrengthRTPCWwise RTPC set from the shot strength for the shoot sound.
private MethodSyncStruct<ShootArguments> syncShootSync message that carries a shot (ShootArguments).

Events​

MemberWhat it is
event Action<Shooter, Pickup, Vector3> OnShootRaised after a shot with the shooter, the item and its launch velocity.
event Action<Shooter, Pickup> PreShootRaised before a shot, with the shooter and the item about to be launched.

Methods​

MemberWhat it is
override void Initialize()Creates the sync used to send shots.
void Shoot(Pickup pickup, float strength, bool isFromNetwork = false, Vector3 direction = null)Undocks the item and launches it with the given strength (0 to 1), playing the sound and sending the shot unless it came from the network.
2 private and internal methods
MemberWhat it is
private Vector3 DefaultShoot(Vector3 direction, Pickup pickup, float strength, bool isApplyingDeviation)Launches a non-arrow item: optionally adds random deviation to its aim, then sets its velocity directly and clears spin.
private void SyncShoot(IPlayer player, Stream stream, ShootArguments args)Network handler: on receive, moves the item to the sent pose and shoots it; the server then relays the shot to other players.

Used in​

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