# Magic Time for Projectile Factory

{% hint style="success" %}
Install the **Projectile Factory Magic Time Integration** package after both [**Projectile Factory**](https://infinitypbr.gitbook.io/infinity-pbr/projectile-factory) and [**Magic Time**](https://infinitypbr.gitbook.io/infinity-pbr/magic-time-local-time-scale) have been installed.
{% endhint %}

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FuAOU6SmJV8WkRu2yW6ku%2FScreen%20Recording%202024-09-15%20at%204.21.45%E2%80%AFPM.gif?alt=media&#x26;token=47ee0d18-7485-43cf-b69a-89caaa8c8123" alt=""><figcaption><p>The projectile (and characters) pass through a "Time Scale Zone", slowing them down.</p></figcaption></figure>

## Turn Projectiles into Magic Time Users

Add the `MagicTimeProjectile` component to your Projectile objects. This class inherits from [`MagicTimeUser`](https://infinitypbr.gitbook.io/infinity-pbr/magic-time-local-time-scale/magic-time-user) and has all the methods that brings.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FcYAAvANoVj8lYknFbt2x%2FScreenshot%202024-09-14%20at%206.23.42%E2%80%AFPM.png?alt=media&#x26;token=3cb84ab5-daac-41e5-8e1a-7dac65c0727a" alt=""><figcaption><p>Here, we see the Projectile will subscribe to the "Global" LocalTimeScale. It will also have it's own LocalTimeScale.</p></figcaption></figure>

{% hint style="info" %}
You can always create a new class which inherits from `MagicTimeProjectile` if you'd like to add any custom logic for your project, including any interactions with custom [**Behaviors**](https://infinitypbr.gitbook.io/infinity-pbr/projectile-factory/projectile-factory-documentation/behaviors) you may have created.
{% endhint %}

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FlnxUnPL2YnPNYsCRntLs%2FScreenshot%202024-09-14%20at%206.33.39%E2%80%AFPM.png?alt=media&#x26;token=a287298b-552f-4922-bf7c-f26095bec0dd" alt=""><figcaption><p>This is a custom class which inherits from <code>MagicTimeProjectile</code>. It has additional logic allowing the projectile to subscribe to additional <code>LocalTimeScale</code> objects, in this case depending on whether it is an "Enemy" or "Player" projectile.</p></figcaption></figure>

## Set Up Projectile Data

Each Projectile has a [`ProjectileData`](https://infinitypbr.gitbook.io/infinity-pbr/projectile-factory/projectile-factory-documentation/projectile/projectile-data) object on it, which can be customized. This also has the "speed" value for the Projectile. The integration comes with `MagicTimeProjectileData` which will calculate speed using the value set modified by the Magic Time values.

Create a new Projectile Data object of this type by right-clicking in your project and choosing `Create/Projectile Factory/Projectile Data/Projectile Data for Magic Time`

Be sure to set the values you'd like, and then populate your Projectiles with this Projectile Data object.

{% hint style="success" %}
For "Damage over Time" projectiles, this will also override those, allowing you to perform damage over time instead of straight values, if you choose. The "over time" will be computed using the `MagicTimeProjectile.CombinedTimeScale()` value.
{% endhint %}

## Add Additional Components

Your **Projectiles** may have many different types of components on them -- they probably have a `ParticleSystem`, but they may also have audio, lighting, or other systems. You can add additional components to your Projectile object which handle the time / speed management of these various components.

### Magic Time User Destroy Or Pool Object

The original `DestroyOrPoolObject` component will send an object back to the pool after a set amount of time. The new version, `MagicTimeUserDestroyOrPoolObject` will do the same thing, but will take into account the objects `TimeScale`, so that it doesn't get destroyed too soon.

### Magic Time User Particle System

The `MagicTimeParticleSystem` component will gather all `ParticleSystems` that are on this Projectile, and set their simulation speed to match the `CombinedValue()` of the `GameTimeUser` object. This way as the object speeds up and slows down, the particle system effects will as well.

{% hint style="success" %}
These components below will connect to the `MagicTimeUser` component on the `MagicTimeUserParticleSystem`, and use the time values from that. They can also be used outside of this, with any `MagicTimeUser` component.
{% endhint %}

### Magic Time User Trail Renderer

Add the `MagicTimeUserTrailRenderer` component  to handle any `TrailRenderer` components on the projectile.

### Magic Time User Audio Source

Add the `MagicTimeUserAudioSource` component to automatically adjust the pitch of audio clips on the Audio Source. This will cache the starting pitch values, so should really be used only for Audio Sources that do not have dynamic clips.

{% hint style="info" %}
There is also a `MagicTimeUserAudioMixer` component, which you can add on your Audio Mixer, and assign the `MagicTimeUser` value to the user you'd like. Generally this would NOT be a single projectile!
{% endhint %}
