> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/projectile-factory/overview-and-quickstart/quick-start-guide/making-lasers-and-similar-attached-projectiles.md).

# 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="/files/NfvuiO7C1AlQLz6wDD7z" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/YfGDYi5WDfuh7qhI2ZB8" alt=""><figcaption></figcaption></figure>

## 1. Add a Projectile Compnent to the Beam

<figure><img src="/files/KT26EeBsX2uHXpwLL89t" alt=""><figcaption></figcaption></figure>

Use the "*Damage Over Time*" [**Projectile Data**](/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile/projectile-data.md), and the "*Laser*" [**Spawn Behavior**](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior.md).

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`**](/magic-pig-games/projectile-factory/projectile-factory-documentation/additional-scripts/raycast-shooter-+-handlers.md) 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="/files/Bq7jOBz9n8qLEwdqkNUs" 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="/files/jIdq26qaJjsmwpisWAMY" alt=""><figcaption></figcaption></figure>

## 4. Set up the Projectile

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

Add a *Parent to Spawn Point* [**Spawn Behavior Modificatio**](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior/spawn-behavior-modification.md)[**n**](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior/spawn-behavior-modification.md).

<figure><img src="/files/DwgfIaLVsM1NYUCdDmuz" 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="/files/GESPX0WqLjIoJ8e3h6tA" alt=""><figcaption></figcaption></figure>

We will add two [**Behaviors**](/magic-pig-games/projectile-factory/projectile-factory-documentation/behaviors.md) 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="/files/61RKraRO6lgFzniIKCsl" 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="/files/gHhrSTe28MzfMDUs8y25" alt=""><figcaption></figcaption></figure>

### Optional: Add Force

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

<figure><img src="/files/BEkFk1sfE6qkCPVjUmxS" 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.
