Projectile2D

Inherited By: AreaProjectile2D, InstancedProjectile2D

Base class for all 2D projectile objects.


Description

The Projectile2D base class manages the internal projectile lifecycle, from initialization to expiration. It directs:

  • Movement calculation (standard and custom).
  • Target acquisition and validation.
  • Collision processing with pierce management.
  • Lifetime countdown.
  • Cleanup, event propagation and projectile chaining.

Note: Projectile instances do not have an object base like Nodes and need the help of a ProjectileProcessor2D to work properly.


Properties



Methods



Signals

projectile_requested(_resource: ProjectileBlueprint2D, _position: Vector2, _destination: Vector2, _target: Node2D)

Emitted when a projectile with secondary projectiles expires.

Requests the creation of its secondary projectiles to the ProjectileProcessor2D.



Property Descriptions

float angular_speed = 0

Current rotation speed (in deg/sec) for seeking projectiles.


Variant arg1 = null

Arbitrary variable for user-defined properties 1.


Variant arg2 = null

Arbitrary variable for user-defined properties 2.


RID cast_shape = PhysicsServer2D.circle_shape_create()

RID used to search for new targets on seeking projectiles.


static PhysicsDirectSpaceState2D current_space

Shared physics space state for collision queries.


Callable custom_collision_method

Callable for the projectile custom collision method.


Callable custom_expired_method

Callable for the projectile custom expired method.


Callable custom_move_method

Callable for the projectile custom move method.


Vector2 destination

Fixed projectile destination.


Vector2 direction

Current movement direction vector (normalized).


Array[RID] excluded_targets = []

List of already hit RID's for piercing and rehit avoidance.


bool first_hit = true

Flag for first hit behavior tracking.


bool is_active = true

Variable state for projectile update validation.


bool is_expired = false

Variable state for projectile lifetime & pierce validation.


bool is_falling_flag = false

Current falling behavior.


float lifetime = 1.0

Remaining lifetime in seconds.


int pierce = 1

Remaining pierces before expiration.


Vector2 position

Current world position.


PhysicsShapeQueryParameters2D query = PhysicsShapeQueryParameters2D.new()

Parameters used to search for new targets on seeking shape casting.


float rehit_cooldown = -1.0

Timer tracking time since last hit.


ProjectileBlueprint2D resource

Fixed projectile blueprint.


float speed = 1000

Current movement speed in pixels/second.


Node2D target

Current homing target (null if no target).


Transform2D transform

Current projectile transform.


bool use_custom_collision_method = false

If true the projectile uses a custom collision method.


bool use_custom_expired_method = false

If true the projectile uses a custom expired method.


bool use_custom_move_method = false

If true the projectile uses a custom move method.



Method Descriptions

void disable()

Disables the projectile and cleans up physics resources.


void move(delta: float)

Handles projectile movement and seeking rotation logic.

Uses delta as the time elapsed since last frame.


void on_expired()

Manages final actions before projectile disposal.

A projectile is considered expired when at least one of these conditions is met:

  • The projectile runs out of lifetime.
  • The projectile runs out of pierce.

void on_pierced(pierced_rid: RID)

Handles pierce count management and target exclusion logic.

Appends pierced_RID to the list of excluded_targets.


float seek_target(_delta: float)

Returns the applied and constraint seeking rotation angle. It also adjusts the projectile direction towards the current target.


void try_retarget()

Attempts to find new targets using shape casting when the current target is lost.


bool update_lifetime(delta: float)

Returns true if the projectile remains active, false if expired


bool validate_collision(colliding_rid: RID, colliding_node: Node)

Returns true if the collision is valid.

A collision is valid if:

  • The projectile is not expired.
  • The projectile is not colliding with areas/bodies it already collided.
  • A lock target projectile is colliding with its assigned target.

Node validate_target(collider: Node)

Returns the validated target node (may be a parent of the original collider).

Seeking projectiles target the global position of the Collision Objects they home in. If you want to seek a parent position, add your Body/Area nodes into the Group "step"