Skip to content

Shooter

namespace Griff.Scenes;
public sealed class Shooter : Component

Fires copies of a Prefab with no code: turrets, cannons, a boss’s spread, or the player’s own gun (see Action). Each shot’s Body is sent off at Speed and it’s turned to face the way it’s going. With Beats set, it fires on the beat of a BeatClock.

This is a component: its saved properties are on its component page.

public string? Action { get; set; }

An input action, e.g. “Fire”: it then fires only while the player holds it, towards the right stick or the mouse (or Direction when neither aims anywhere). Empty fires by itself.

public int BeatOffset { get; set; }

Steps this many beats later: with two turrets on every 2 beats, one 1 beat later, they take turns.

public int Beats { get; set; }

Steps to the music of a BeatClock: fires on every this many beats instead of every Interval seconds, once Delay has passed (and, with an Action, while it’s held). 0 goes by seconds.

public string? Clock { get; set; }

The entity whose BeatClock it steps to. Empty follows the first in the scene.

public int Count { get; set; }

Shots in each volley, fanned out across Spread.

public float Delay { get; set; }

Seconds before the first shot.

public Vector2 Direction { get; set; }

Which way to fire without a target (or an aim, for the player).

public float Interval { get; set; }

Seconds between shots (unless it steps to the Beats).

public bool NeedsSight { get; set; }

With a Target, only fire when nothing solid is in the way: no shooting through walls.

public Vector2 Offset { get; set; }

Where shots appear relative to the entity, in world units.

public string? Prefab { get; set; }

The prefab to fire, e.g. “Bullet” (Assets/Prefabs/Bullet.prefab). It needs a Body to fly.

public float Range { get; set; }

With a Target, only fire when it’s this close. 0 fires at any distance.

public bool Running { get; set; }

Untick it to hold fire. Switches tick and untick it.

public string? Sound { get; set; }

A sound played with each volley, e.g. “Sounds/shoot.wav”.

public float Speed { get; set; }

How fast shots fly, in world units per second.

public float Spread { get; set; }

Degrees the volley fans across; with one shot, how far off aim it may randomly go.

public string? Target { get; set; }

The name of an entity to aim at, e.g. “Player”. Empty fires in Direction.

public IEnumerable<Vector2> VolleyAround(Vector2 aim)

The directions of one volley’s shots around aim (a unit vector).

public event Action<Entity>? Fired

Raised with each shot fired, e.g. to give it a damage or a color.