---
description: v1.0
---

# Making Lasers & Similar Attached Projectiles

Sometimes a projectile doesn't move. Lasers, flamethrowers, and any other kind of projectile that is intended to stay in one spot, or attached to a `Transform`, can be created! This guide will walk through the setup for a laser projectile which stays attached to the **Spawn Point**.

{% embed url="https://youtu.be/5wpwJ49yKfs" %}

We will be using the **Magic Arsenal by Archanor VFX** on the Asset Store for this. The "_Acane Beam_" is the beam itself, using a `LineRenderer`. The other two parts will be attached to the muzzle position and the "hit point" -- the place where the beam collides with another object.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FWKxxMQOyEuVa31vzWzQl%2FScreen%20Recording%202024-04-06%20at%208.47.12%E2%80%AFPM.gif?alt=media&#x26;token=8dbbb89c-64be-4e03-8b55-7e86d35f777d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FYYYq9BYdgz92lqUKQhVR%2FScreenshot%202024-04-06%20at%208.12.47%E2%80%AFPM.png?alt=media&#x26;token=3ba5e43a-97e2-4aad-93df-b898c45282fe" alt=""><figcaption></figcaption></figure>

## 1. Add a Projectile Compnent to the Beam

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FmpxI1GmbpScJA3Ypjptz%2FScreenshot%202024-04-06%20at%208.15.19%E2%80%AFPM.png?alt=media&#x26;token=9e5fe15f-1004-4825-b6f9-c20ae095a4bf" alt=""><figcaption></figcaption></figure>

Use the "_Damage Over Time_" [**Projectile Data**](../../projectile-factory-documentation/projectile/projectile-data), and the "_Laser_" [**Spawn Behavior**](../../projectile-factory-documentation/spawn-behavior).

The `DamageOverTime` class overrides how the damage is calculated, to multiply it by `Time.deltaTime`.

```csharp
protected override float CalculateDamage() => damage * Time.deltaTime;
```

_Laser_ **Spawn Behavior** is set up for a laser, including blocking multiple shots. Check the object for specifics.

## 2. Add a Raycast Shooter Component

The [**`RaycastShooter`**](../../projectile-factory-documentation/additional-scripts/raycast-shooter-+-handlers) class is provided in **Projectile Factory,** and will fire a `raycast` forward, and pass hits to handlers on other objects in the prefab. Be sure to assign the _Raycast Origin_ value.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FAqyhZA5SrFFs1kAjK6QZ%2FScreenshot%202024-04-06%20at%208.19.44%E2%80%AFPM.png?alt=media&#x26;token=07a79e5b-7a78-4084-a375-4202c06caa14" alt=""><figcaption></figcaption></figure>

## 3. Add a Line Renderer Length Component

The **`LineRendererLength`** class handles the setting the length of the `LineRenderer` to the distance of any collision, or the max distance provided. This compoennt implements `IHandleRaycasts`, so the Raycast Shooter will pass the `Hit` value to this class.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FItyuGHFDS9oAJYxK1tqr%2FScreenshot%202024-04-06%20at%208.22.10%E2%80%AFPM.png?alt=media&#x26;token=2decda58-367d-4e61-8e0a-89cdb39b2d93" alt=""><figcaption></figcaption></figure>

## 4. Set up the Projectile

### **Add a Spawn Behavior Modification**

Add a _Parent to Spawn Point_ [**Spawn Behavior Modificatio**](../../projectile-factory-documentation/spawn-behavior/spawn-behavior-modification)[**n**](../../projectile-factory-documentation/spawn-behavior/spawn-behavior-modification).

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2Ft3h4Y24Oym0jmn480eoY%2FScreenshot%202024-04-06%20at%208.25.07%E2%80%AFPM.png?alt=media&#x26;token=dca2e372-89e1-429f-bb46-7bcaf0e5fcde" alt=""><figcaption></figcaption></figure>

There are no exposed parameters here -- this does one thing, and one thing only. After spawning, the **Projectile** will be parented to the **Spawn Point** `transform`.

### Add Behaviors

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FFVCoua0EGOL2VF0PC17A%2FScreenshot%202024-04-06%20at%208.28.10%E2%80%AFPM.png?alt=media&#x26;token=64ff0a8e-96f4-4d21-8d9d-b57e011e9a81" alt=""><figcaption></figcaption></figure>

We will add two [**Behaviors**](../../projectile-factory-documentation/behaviors) to this **Projectile**. First, _Destroy on Spawner Stop_ will destroy (or pool) the projectile when the spawner stops -- in the demo, this is when the "shoot" button is released.

_Collision at Line Render End_ will get the **Projectile** to check for a collision at the end of the `LineRenderer`, with the radius selected.

## 5. Set up the Muzzle & Impact Particles

The _Muzzle_ and _Impact_ particles aren't part of the **Projectile** directly. Instead, they'll be child objects of the Projectile, and will be handled by other scripts.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FTqz8t5PYMGUIGA9K8AeX%2FScreenshot%202024-04-06%20at%208.32.08%E2%80%AFPM.png?alt=media&#x26;token=0707adc9-29ce-444f-8c08-d5cf3da2dba7" alt=""><figcaption><p>Make these children of the <strong>Projectile</strong></p></figcaption></figure>

### Position the Objects

The _Muzzle_ object should be positioned at local 0, 0, 0 -- basically the same spot as the `LineRenderer` origin, which will be the Spawn Point.

Add a `SetPositionFromRaycast` class to the _Impact_ object. Be sure to assign the "Plumbing" values. This implements `IHandleRaycasts`, so the `RaycastShooter` will handle passing data to this script, which is how it knows where to set the position.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FZePvj9gmoGUagTLg8mBS%2FScreenshot%202024-04-06%20at%208.32.03%E2%80%AFPM.png?alt=media&#x26;token=cc53c4bf-6bbf-4e2a-a9f6-763b249dee05" alt=""><figcaption></figcaption></figure>

### Optional: Add Force

You can also add an [**`AddForce`**](../../projectile-factory-documentation/additional-scripts/project-force) component to the Impact object. This will add physics force at that position, helping the game come alive.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FRBI7BQ7NrES2ERtDbxrP%2FScreenshot%202024-04-06%20at%208.35.54%E2%80%AFPM.png?alt=media&#x26;token=c557e416-e9d2-4a5b-87f0-07235dab1111" alt=""><figcaption></figcaption></figure>

## 6. Set the Layer of the Projectile

Don't forget to change the layer of your projectile! And then save this as a `Prefab`.

## Done!

That's it! Bring this onto a **Projectile Spawner** the same as any other **Projectile**, and it'll function exactly the same, but with its own unique logic and behavior.
