Skip to main content

RaycastProjectile

A class in Root.Township, the global namespace.

Projectile hit check that sphere-casts along the rigidbody's velocity each fixed update instead of relying on colliders. By default it only runs on the server.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private ColliderAltaEvent collidedInspector event fired with the hit collider.
private LayerMask hitLayersLayers the cast can hit. Triggers are ignored.
private bool isOnlyOnServerWhen true (default), StartRaycasting only does anything on the server.
private bool isStoppingAfterFirstHitWhen true, stops casting after the first hit.
private IUnityUpdateMethod raycastUpdateHandle for the registered fixed update method.
private float sizeRadius of the sphere cast.
private Rigidbody targetRigidbodyRigidbody whose velocity sets the cast direction and length. Hits on it are ignored.
private Transform targetTransformTransform the cast starts from. Defaults to this object's transform.

Events​

MemberWhat it is
event Action<RaycastHit> OnCollidedFires with the RaycastHit each time the cast hits something not on the projectile's own rigidbody.

Methods​

MemberWhat it is
void StartRaycasting()Registers the per-fixed-update cast. Does nothing on clients when isOnlyOnServer is set.
void StopRaycasting()Deregisters the per-fixed-update cast.
3 private and internal methods
MemberWhat it is
private void OnDestroy()Stops the raycast update.
private void OnValidate()Editor: if size is unset, copies the radius of a child SphereCollider.
private void UpdateRaycast()Sphere-casts over the last fixed step's movement; on a hit fires collided and OnCollided, and may stop.

Used in​

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