---
description: A detailed guide on how to use the projectile system.
---

# Projectile System

While Projectiles (Physical Bullets) can be used, FPS Framework uses Hitscan (Raycast) by default, which are the most common performant method in all first-person shooter games. If you would like to use hitscan you can check this out.

## Creating a new projectile

To create a new projectile first create an empty game object and add the component **"Projectile"** to it. Your game object's inspector should look like this:

<div align="left"><figure><img src="https://512600823-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLQgz9gGwkU5HhRwKT3te%2Fuploads%2FnSnABADzoTWhpzwrLxRx%2FScreenshot%202024-02-28%20022123.png?alt=media&#x26;token=42147bd9-f75a-4a89-918b-3e624c0185f9" alt="" width="536"><figcaption><p>Default projectile's inspector</p></figcaption></figure></div>

This is the default values (Could be different depencing on the current version of FPS Framrwork that you are using.

### Fields

<table><thead><tr><th width="235">Name</th><th>Description</th></tr></thead><tbody><tr><td>Hittable layers</td><td>The layers which this projectile can detect</td></tr><tr><td>Decal direction</td><td>The direction of the decal according to the normal value of the raycast</td></tr><tr><td>Penetration strength</td><td>This amount, which may be referred to as the projectile's "health," is set by the "Default Decal" component and decreases each time the projectile hits an item. The default health damage value is 10 in the event that this component is unavailable.</td></tr><tr><td>Speed</td><td>The speed of the projectile</td></tr><tr><td>Gravity</td><td>The gravity multiplier to this projectile. A value of 2 is equal to Physics.gravity * 2</td></tr><tr><td>Force </td><td>The force the projectile can apply when it hits an object.</td></tr><tr><td>Lifetime</td><td>The time after which the projectile automatically destroys itself.</td></tr><tr><td>Default decal</td><td>The default hit impact effect if there's no "Custom Decal" component on the object that got hit.</td></tr><tr><td>Destroy on impact</td><td>If on the projectile will automatically destroy itself on the first hit.</td></tr><tr><td>Use source velocity</td><td>If on the projectile will add the force of the shooter to its initial velocity.</td></tr><tr><td>Use auto scaling</td><td>If on the projectile will scale itself to always look the same to the shooter.</td></tr><tr><td>Scale multiplier</td><td>The scale of the projectile which the projectile needs to maintain, this is not affected by "Use auto scaling" toggle.</td></tr><tr><td>Range</td><td>The range of the projectile in which it can deal damage.</td></tr><tr><td>Damage range curve</td><td>How the damage is affected by its travel distance.</td></tr></tbody></table>

### Ignoring hits

To ignore hits from all projectiles to a certian game object, you can do these

* Assgin a layer to that game object and remove it from the hittable layers
* Add the component "IgnoreHitDetection" to the game object you want to ignore hits.

This is how your game object's inspector that ignores hits look like:

<div align="left"><figure><img src="https://512600823-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLQgz9gGwkU5HhRwKT3te%2Fuploads%2Fso93xdbKjTA44BdGMpQ5%2FScreenshot%202024-02-28%20024313.png?alt=media&#x26;token=9086143f-8073-4e07-b0a5-86b7df197210" alt="" width="548"><figcaption><p>Ignore hit detection's inspector</p></figcaption></figure></div>

### Hit events

The projectile can send messages to your custom scripts via a callback function like unity's callbacks e.g OnTriggerEnter(). To add these functions to your script you need to implement the interface "IOnHit" or any of its variants to your script like this:

```csharp
using Akila.FPSFramework;

public class Test : MonoBehaviour, IOnHit
{
    public void OnHit(HitInfo hitInfo)
    {
        throw new System.NotImplementedException();
    }
}
```

The function "OnHit()" will be called when the projectile hit any object with this component along with a collider. You can test it by printing a message to the console. The function has a argument of "HitInfo" which contains useful information about your hit.

The hit functions are called from the interface "IOnAnyHit" as well as "IOnHit" and their variants.

### Transferring into explosive projectile

You only need to add the "Explosive" component to the same game object that already has the projectile on it in order to change this projectile from being a simple "Bullet" to an explosive one. The rest is explanined in [Explosive](../../explosive)
