Scripting
One-line effects
The player took damage
The usual bundle for a hit on the player: a damage number, the side the hit came from, a hurt moment or a plain PassForgeScreenShake.Shake, and the low health loop.
using PassForge.Effects;
using UnityEngine;
// Everything a hit on the player shows: the number, the side it came from, a hurt moment or a shake, and the
// low health loop.
public class PlayerHealth : MonoBehaviour
{
[SerializeField] int m_Health = 6;
[SerializeField] PassForgeMoment m_Hurt; // such as a red flash, a shake and a rumble
[SerializeField] PassForgeMoment m_LowHealth; // such as a heartbeat look set to Repeat
bool m_Low;
public void TakeHit(Transform attacker)
{
m_Health = Mathf.Max(0, m_Health - 1);
PassForgeDamageNumbers.Spawn(transform, 1f); // the heart the hit took, over the player
if (attacker != null)
PassForgeDamageIndicator.Show(attacker); // which side it came from, following the attacker
if (m_Hurt != null)
m_Hurt.Play();
else
PassForgeScreenShake.Shake(0.5f, 0.4f); // shakes add up, to at most 1
bool low = m_Health > 0 && m_Health <= 2;
if (low != m_Low && m_LowHealth != null)
{
m_Low = low;
m_LowHealth.SetPlaying(low);
}
}
}
Rewind the picture
PassForgeVhsRewind.recording keeps the last seconds of the picture, and PassForgeVhsRewind.Rewind plays them backward. A moment with a VHS Rewind step records by itself while it is enabled.
using PassForge.Effects;
using UnityEngine;
// A rewind on a button. Only the picture rewinds: move the player back from your own code, as the moment example
// with On Played does.
public class RewindButton : MonoBehaviour
{
// Recording keeps the last seconds of the picture, about 15 MB at 1080p, so it is on only while this is.
void OnEnable() => PassForgeVhsRewind.recording = true;
void OnDisable() => PassForgeVhsRewind.recording = false;
public void Rewind()
{
if (!PassForgeVhsRewind.isRewinding)
PassForgeVhsRewind.Rewind(1.5f);
}
}
Stop every effect
Before a respawn, a camera cut or the main menu. PassForgeMoment.StopNamed stops a moment with no reference to it.
using PassForge.Effects;
// Before a respawn, a camera cut or the main menu: ends what scripts and moments started.
public static class StopEffects
{
public static void StopAll()
{
PassForgeScreenShake.Stop();
PassForgeShockwaves.Clear();
PassForgeFlashLights.Clear();
PassForgeScreenFlash.Stop();
PassForgeVhsRewind.Stop();
PassForgeTransition.Stop(); // takes a cover off at once
PassForgeSlowMotion.Stop(); // gives the game its own time scale back
PassForgeDamageNumbers.Clear();
PassForgeDamageIndicator.Clear();
PassForgeLensBlood.Clear();
PassForgeAfterimage.ClearAll();
PassForgeTether.ClearStrikes();
PassForgePings.Clear();
PassForgeRumble.Stop();
PassForgeMoment.StopNamed("Alarm"); // a repeating moment, with no reference to it
}
}
Lightning between two objects
PassForgeTether.Strike flashes a bolt between two points with no component, and PassForgeTether.ChainStrike arcs from target to target. A Tether component holds a beam on its target until it is cleared.
using System.Collections.Generic;
using PassForge.Effects;
using UnityEngine;
// Lightning from a staff: one bolt, chain lightning, and a beam held on a target.
public class ZapStaff : MonoBehaviour
{
[SerializeField] Transform m_Tip;
[SerializeField] PassForgeTether m_Beam; // a Tether component on the staff, for a beam that stays
// A bolt between two points for a moment, with no component needed.
public void Zap(Transform enemy) => PassForgeTether.Strike(m_Tip.position, enemy.position);
// From the staff to the first enemy, then on from enemy to enemy, following them as they move.
public void ChainZap(IList<Transform> enemies) => PassForgeTether.ChainStrike(m_Tip, enemies, 0.5f);
// A beam from the staff to a target until it is let go.
public void Hold(Transform target) => m_Beam.target = target;
public void LetGo() => m_Beam.target = null;
}
Afterimages on a dash
An Afterimage switched on leaves ghosts; switched off, it drops the ghosts it left at once. To let a trail fade, stop it leaving new ghosts first: a Color with no alpha leaves none, and each ghost keeps the color it was left with. A Moment's Afterimage Burst step does the same with no code. PassForgeAfterimage.ClearAll drops every ghost at once, after a teleport or a camera cut.
using System.Collections;
using PassForge.Effects;
using UnityEngine;
// Ghosts behind a dash, and none across a teleport.
public class DashTrail : MonoBehaviour
{
[SerializeField] PassForgeAfterimage m_Afterimage; // switched off in the scene
Color m_Color;
void Awake() => m_Color = m_Afterimage.color;
public void StartDash(bool rainbow)
{
StopAllCoroutines();
m_Afterimage.color = m_Color;
m_Afterimage.hueCycleSpeed = rainbow ? 1.5f : 0f;
m_Afterimage.enabled = true;
}
// Switched off, an Afterimage drops its ghosts at once, so the trail first stops leaving new ones and switches
// off once the last ones have faded.
public void EndDash() => StartCoroutine(FadeTrail());
IEnumerator FadeTrail()
{
m_Afterimage.color = new Color(m_Color.r, m_Color.g, m_Color.b, 0f); // no new ghosts
yield return new WaitForSeconds(m_Afterimage.fadeTime * 4f);
m_Afterimage.enabled = false;
m_Afterimage.color = m_Color;
}
public void Teleport(Vector3 to)
{
transform.position = to;
PassForgeAfterimage.ClearAll(); // no ghosts across the jump; also after a camera cut
}
}
Blood on the lens
PassForgeLensBlood.SplatFrom takes a world position and lands the splat where it is on screen, kept off the middle. PassForgeLensBlood.Wipe cleans the lens.
using PassForge.Effects;
using UnityEngine;
// Blood on the camera lens, kept off the middle of the screen.
public static class LensBloodHits
{
// Lands where the enemy is on screen, or on the edge of its side when the camera does not see it.
public static void HitUpClose(Vector3 enemy) => PassForgeLensBlood.SplatFrom(enemy, LensBloodSplat.HeavyHit);
public static void HitFromSide(Vector3 attacker) => PassForgeLensBlood.SplatOnEdge(attacker);
public static void PointBlank() => PassForgeLensBlood.Splat(LensBloodSplat.ShotInTheFace);
// Green alien blood beside red, in a color of its own.
public static void AlienHit(Vector3 alien, Color green)
{
PassForgeLensBlood.SplatFrom(alien, LensBloodSplat.Hit, 1f, green);
}
// Blood stays until it fades, across a respawn and a scene load too: wipe it on a heal or a respawn.
public static void Healed() => PassForgeLensBlood.Wipe(0.5f);
}
Gamepad rumble
PassForgeRumble.Play(strength, seconds) rumbles every gamepad and buzzes a phone for strong rumbles. The player's shake setting scales it.
using PassForge.Effects;
// Gamepad rumble, and a phone buzz for strong ones. Gamepads need the Input System package, and the player's shake
// setting scales it.
public static class Rumble
{
public static void Explosion() => PassForgeRumble.Play(1f, 0.4f);
// A stronger or longer rumble meanwhile takes over.
public static void Hit() => PassForgeRumble.Play(0.4f, 0.15f);
public static void Paused() => PassForgeRumble.Stop();
}