Skip to main content

ContactProjectile

An abstract class in Root.Township, Alta.Impact.

Base for an old projectile that reacts when its impactor hits something. It records the hit direction and calls OnContact when the impactor resets. Only NetworkContactProjectile derives from it, and that is obsolete.

Constructors​

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

Properties​

MemberWhat it is
Rigidbody Rigidbody { get; set; }The projectile's rigidbody, stopped in ResetEffect. Must be set before a hit resets.
protected abstract bool HasContacted { get; }Whether the projectile has already hit something. Set by the subclass.
protected Quaternion LastHitRotation { get; private set; }Rotation facing back along the last hit direction or collision normal, for placing a hit effect.

Methods​

MemberWhat it is
void OnCollided(Collision collision, bool isHitting, ImpactTool tool)Records the first contact's normal as LastHitRotation.
void OnHit(ImpactHitWithTool hit, ImpactTool tool)Records the reverse of the tool hit's direction as LastHitRotation, or straight up if the hit had no direction.
void ResetEffect()Called by the impactor on reset: stops the rigidbody and calls OnContact.
protected virtual void Awake()Registers this projectile with every ImpactGenerator in its children so their reset calls ResetEffect.
protected abstract void OnContact()Subclass hook run when the impactor resets after a hit.