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.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour,IToolHitDependant,IImpactorResetEffect,IShootable,ITargetPointer - Derived types
ProjectileAltaEvent,ProjectileUnityEvent - Documented in Combat, damage and death
Constructors
| Member | What it is |
|---|---|
Projectile() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
13 private and internal fields
| Member | What it is |
|---|---|
private MethodSyncStruct<bool> collidedSync | Method sync for the collided message. |
private ColliderGroup colliders | Backing field for Colliders. |
private bool collidesOnlyOnce | If true, only the first collision counts. |
private float destroyDuration | Seconds after firing before the server destroys the projectile. Default 60. |
private ColliderGroup disabledAgainst | Collider group the projectile ignores, usually the shooter's. |
private ProjectileAltaEvent fired | Event behind Fired. |
private FixedImpactor[] impactors | Impactors charged when fired; SetupDamageMultiplier scales them. |
private bool isDestroyedOnCollision | If true, the projectile is destroyed when it hits something on layerMaskForDestruction. |
private bool isFired | True once shot; collisions before that are ignored. |
private LayerMask layerMaskForDestruction | Layers that destroy the projectile on hit. Empty means all layers. |
private AltaEvent onDestroyed | Event played when a collision destroys the projectile. |
private Rigidbody rigidbody | Backing field for Rigidbody. |
private MethodSync syncFired | Method sync for the fired message. |
Properties
| Member | What 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
Events
| Member | What it is |
|---|---|
event Action<Projectile> Collided | Raised on the server when it hits something, and on clients when told. |
event Action<Projectile> Fired | Raised when the projectile is fired, on every side. |
Methods
| Member | What 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
| Member | What 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: