codeAPI Reference

s&box Projectile: Collision-based projectile

calendar_today May 12, 2026 schedule ~1 min read person PatrickJr verified 50

Projectile Component API Reference

Projectile is a Component that implements ICollisionListener for collision-based projectiles. It destroys itself on collision and can notify the instigator of hits.

Type Signature

CSHARP
public class Projectile : Component, Component.ICollisionListener
{
    [RequireComponent] public Rigidbody Rigidbody { get; set; }

    [Sync(SyncFlags.FromHost)] public Player Instigator { get; set; }

    protected TimeSince TimeSinceCreated;

    protected virtual void OnHit(Collision collision = default);
    protected void NotifyHit(IDamageable target, Vector3 point);
    public void UpdateDirection(Vector3 direction, float speed);
}

Properties

Methods

OnHit(Collision collision)

Called when the projectile hits something. Default implementation destroys the GameObject. Override for custom hit behavior.

NotifyHit(IDamageable target, Vector3 point)

Notifies the instigator that their projectile hit a target. Currently a TODO for hitmarker implementation.

UpdateDirection(Vector3 direction, float speed)

Updates the projectile's direction and velocity. Sets rotation to look at direction and sets rigidbody velocity.

ICollisionListener Implementation

Usage

CSHARP
public class MyProjectile : Projectile
{
    protected override void OnHit(Collision collision)
    {
        // Custom hit logic
        var explosion = GameObject.Clone(explosionPrefab, WorldTransform);
        explosion.NetworkSpawn();
        
        base.OnHit(collision);
    }
}

Notes

  • Tags itself with "projectile" on start
  • Ignores collisions with the instigator player
  • IsProxy check ensures only host handles collisions
  • TimeSinceCreated reset on enable
  • Useful for bullets, rockets, grenades, etc.
Was this helpful?