> For the complete documentation index, see [llms.txt](https://godot-essentials.gitbook.io/addons-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://godot-essentials.gitbook.io/addons-documentation/components/projectile-component.md).

# 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.&#x20;

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.&#x20;

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)*&#x20;

*follow\_stopped(target: Node2D)*&#x20;

*target\_swapped(current\_target: Node2D, previous\_target:Node2D)*&#x20;

*bounced(position: Vector2)*

*penetrated(remaining\_penetrations: int)*&#x20;

*penetration\_complete()*
