> For the complete documentation index, see [llms.txt](https://docs.allout.game/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allout.game/core-engine-concepts/projectiles.md).

# Projectiles

CSL does not have a built-in projectile component. Use a prefab with a script for movement and either a trigger collider or a range query for hits.

## Trigger-based projectile

Create a prefab with:

* A sprite or `Spine_Animator`
* A `Circle_Collider` with **Is Trigger** enabled
* The component below

```go
Damageable :: class : Component {
    @ao_serialize health: float = 100;

    take_damage :: method(amount: float) {
        health -= amount;
    }
}

Projectile :: class : Component {
    direction: v2;
    owner: Entity;
    @ao_serialize speed: float = 12;
    @ao_serialize damage: float = 25;
    @ao_serialize lifetime: float = 3;
    spent: bool;

    ao_start :: method() {
        collider := entity.get_component(Circle_Collider);
        collider.is_trigger = true;
        collider.on_trigger_start = proc(self: Collider, other: Collider) {
            projectile := self.entity.get_component(Projectile);
            projectile.hit(other.entity);
        };

        entity.queue_for_destruction(lifetime);
    }

    ao_update :: method(dt: float) {
        entity.add_local_position(direction * speed * dt);
    }

    hit :: method(other: Entity) {
        if spent return;
        if other == owner return;

        target := other.get_component(Damageable);
        if target == null return;

        spent = true;
        target.take_damage(damage);
        entity.destroy();
    }
}
```

Spawn the prefab with `Scene.instantiate`, then initialize its component:

```go
spawn_projectile :: proc(
    prefab: Prefab_Asset,
    owner: Entity,
    position: v2,
    direction: v2
) {
    assert(length_squared(direction) > 0, "projectile direction must be nonzero");

    projectile_entity := Scene.instantiate(prefab, position);
    projectile := projectile_entity.get_component(Projectile);
    projectile.owner = owner;
    projectile.direction = normalize(direction);
}
```

Run projectile movement and damage in the normal shared gameplay path. Prediction runs the same code on clients and server, so do not guard it with `Game.is_server()`.

## Fast projectiles

Trigger overlap checks can miss a small target when a projectile crosses it between simulation frames. For fast projectiles, query several points along the movement segment with `Scene.get_all_components_in_range`, or use a larger collision radius. See [Navmesh and Collision](/core-engine-concepts/navmesh-and-collision.md#fast-movement-hits-simple-sub-stepping) for a sub-stepping example.

Call `SFX.play` from the same predicted hit path. The sound system reconciles the predicted sound with the server result.
