Skip to main content

Projectile

A class in Root.Township, the global namespace.

A networked thrown or shot object (arrows and the like) that charges its impactors when fired and reports its first hit. The server decides hits and destruction; it is never saved and is destroyed 60 seconds after firing by default.

Constructors​

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

Fields​

13 private and internal fields
MemberWhat it is
private MethodSyncStruct<bool> collidedSyncMethod sync for the collided message.
private ColliderGroup collidersBacking field for Colliders.
private bool collidesOnlyOnceIf true, only the first collision counts.
private float destroyDurationSeconds after firing before the server destroys the projectile. Default 60.
private ColliderGroup disabledAgainstCollider group the projectile ignores, usually the shooter's.
private ProjectileAltaEvent firedEvent behind Fired.
private FixedImpactor[] impactorsImpactors charged when fired; SetupDamageMultiplier scales them.
private bool isDestroyedOnCollisionIf true, the projectile is destroyed when it hits something on layerMaskForDestruction.
private bool isFiredTrue once shot; collisions before that are ignored.
private LayerMask layerMaskForDestructionLayers that destroy the projectile on hit. Empty means all layers.
private AltaEvent onDestroyedEvent played when a collision destroys the projectile.
private Rigidbody rigidbodyBacking field for Rigidbody.
private MethodSync syncFiredMethod sync for the fired message.

Properties​

MemberWhat it is
ColliderGroup Colliders { get; }The projectile's own colliders.
bool HasCollided { get; private set; }True after the first hit (if set to collide only once).
Rigidbody Rigidbody { get; }The projectile's rigidbody.
ITarget Shooter { get; set; }The target that fired it, for AI. Shooting does not set it.
Collider SurfaceCollider { get; private set; }The collider it hit. Null on clients.
Vector3 SurfaceNormal { get; private set; }Surface normal at the hit point.
Vector3 SurfacePoint { get; private set; }World point where it hit.
1 private and internal property
MemberWhat it is
private ITarget Alta.Intelligence.ITargetPointer.Target { get; }The target pointed at is the Shooter, so hits can be traced back to who fired.

Events​

MemberWhat it is
event Action<Projectile> CollidedRaised on the server when it hits something, and on clients when told.
event Action<Projectile> FiredRaised when the projectile is fired, on every side.

Methods​

MemberWhat it is
override void Initialize()Sets up the fired and collided messages and marks the entity as not saved.
void SetupDamageMultiplier(float damageMultiplier)Multiplies the damage of all its impactors.
void Shoot(Vector3 velocity, ColliderGroup collidersToIgnore = null)Launches it with a velocity, optionally ignoring some colliders (such as the shooter). Server: schedules destruction and syncs the shot.
void Shoot(Vector3 velocity)Launches it with a velocity, optionally ignoring some colliders (such as the shooter). Server: schedules destruction and syncs the shot.
7 private and internal methods
MemberWhat it is
private IEnumerator DestroyAfterDuration() (iterator)Server coroutine that destroys the projectile destroyDuration seconds after it is fired.
private void Alta.Impact.IToolHitDependant.OnCollided(Collision collision, bool isHitting, ImpactTool tool)Tool collision callback: once fired, records the first contact as a collision.
private void OnCollision(Vector3 point, Vector3 normal, Collider collider)Server: records where it hit, tells clients, fires Collided and destroys the projectile if the hit layer allows.
private void Alta.Impact.IToolHitDependant.OnHit(ImpactHitWithTool hit, ImpactTool tool)Tool hit callback: once fired, records the hit as a collision.
private void Alta.Impact.IImpactorResetEffect.ResetEffect()Impactor reset callback; does nothing.
private void SyncCollided(IPlayer player, Stream stream, bool isDestroying)Client handler for the collided message: sets the hit point and normal, fires Collided and plays the destroyed event.
private void SyncFired(IPlayer player, Stream stream)Fired message: sends velocity and the ignored collider group; clients launch the projectile the same way.

Used in​

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