Addons documentation
  • 😄Getting Started
  • 🧩Components
    • 👟Godot Essentials Motion Component
      • 🤸Top-Down Movement Component
      • 🤾Platform Movement Component
      • 🔲Grid Movement Component
    • 💓Health Component
    • 🎥Shake Camera Component
    • 🌪️Rotator Component
    • 🚀Projectile component
    • 🔁Finite State Machine
  • ⏳Autoload
    • 🎒Helpers
    • 🎧AudioManager
    • 🎬Scene Transicioner
    • ⚙️Environment variables
    • 🏆Achievements
  • 🎮Examples
    • 🧗‍♂️Alys - Precision platformer
Powered by GitBook
On this page
  • Getting started
  • Exported parameters
  • Speed
  • Homing
  • Penetration
  • Bounce
  • Accessible normal parameters
  • Once upon the scene tree
  • Interactive functions
  • move(delta: float = get_physics_process_delta_time())
  • swap_target(new_target: Node2D)
  • stop_follow_target()
  • begin_follow_target(new_target: Node2D)
  • target_position() -> Vector2
  • bounce(new_direction: Vector2) -> Vector2
  • Signals
  1. Components

Projectile component

Imagine placing this component in any scene representing a projectile in your video game, and it is ready for action. It provides common functionalities for standard projectiles.

Getting started

This node functions like the others, serving as a child of another node. In this case, it is not restricted to only CharacterBody2D, as bullets are typically Area2D objects.

Exported parameters

Speed

  • Max speed

  • Acceleration

The max speed as the name say, defines the maximum reachable limit of speed that will be apply to the velocity.

The getter of the speed modify the value based on speed_reduction_on_penetration parameter

The acceleration makes smoother to reach the maximum speed if you want to increase the juiciness of the movement. In case you don't want it just assign a zero value to it and the node will reach the maximum speed immediately

Homing

  • Homing distance

  • Homing strength

The homing distance defines the maximum distance the projectile will pursue the target if the target is defined. Leave it at zero if there is no distance limit.

The purpose of homing_strength is to provide fine-grained control over how aggressively the projectile homes in on the target.

Penetration

  • Max penetrations

  • Speed reduction on penetration

The max penetrations is an integer value that determines how many times the projectile can penetrate before emitting the penetration_complete signal. We do not queue-free the node as we leave the behavior to the user, allowing them to handle it by connecting to the signal.

The speed reduction on penetration decreases the speed by this amount back to the original maximum speed each time a penetration occurs.

Bounce

  • Bounce enabled

  • Bounce times

The bounce enabled setting allows the projectile to bounce upon collision or another type of event.

The bounce times parameter determines the number of times this projectile can bounce.

Accessible normal parameters

  • projectile: Node2D

  • direction: Vector2

  • target: Node2D

  • follow_target: bool

  • penetration_count

  • bounced_positions: Array[Vector2]

Once upon the scene tree

  • Connects to the signal follow_started

When this projectile starts to follow a target, the component checks if the target can be followed. This means:

  1. The target is not null.

  2. The homing distance to the target is less than the defined value.

If these conditions are met, the homing behavior begins. Depending on the homing_strength, the projectile starts to follow the target smoothly.

Interactive functions

move(delta: float = get_physics_process_delta_time())

The projectile starts moving in the direction and at the maximum speed defined as parameters. In this state, the projectile uses look_at to orient itself towards the provided direction.

swap_target(new_target: Node2D)

The target is swapped to the provided one as parameter and emit the signal target_swapped

stop_follow_target()

The projectile stop following the target if this is defined. This function set the target to null and follow_target to false

begin_follow_target(new_target: Node2D)

The projectile begins to follow the target, and this behavior is activated. This function set the target to new_target and follow_target to true

target_position() -> Vector2

If a target is defined, this function returns the normalized direction from this projectile to the target. It returns Vector2.ZERO when the target is null.

bounce(new_direction: Vector2) -> Vector2

The projectile bounces in the direction defined by the new_direction parameter if bouncing is enabled and there are remaining bounces for this projectile. Every succesfull bounce append the position to the bounced_positions array

Typically, you pass the wall_normal as a parameter to bounce in the opposite direction, but we don't want to restrict things; the new_direction is flexible. This action also emits the bounced signal.

Signals

follow_started(target:Node2D)

follow_stopped(target: Node2D)

target_swapped(current_target: Node2D, previous_target:Node2D)

bounced(position: Vector2)

penetrated(remaining_penetrations: int)

penetration_complete()

PreviousRotator ComponentNextFinite State Machine

Last updated 1 year ago

🧩
🚀