Forum begins after the advertisement:
[General] Creating Thunder Loop (Lightning Ring Evolution)
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [General] Creating Thunder Loop (Lightning Ring Evolution)
- This topic has 0 replies, 1 voice, and was last updated 5 months, 2 weeks ago by Joseph Tang.
-
AuthorPosts
-
June 7, 2024 at 5:38 pm #15043::
This is a post to provide detail on how to create the Thunder Loop Weapon Evolution for our Rogue-like Shoot-em Up series.
To do this we’ll be going through 3 things:- Setting up a Thunder Loop VFX.
- Writing the Thunder Loop Projectile Script.
- Creating the Weapon Data and Evolution Data.
For convenience, below are the links to the article and the video that our code & scriptable objects will be based off:
- Article Link: https://blog.terresquall.com/2023/12/creating-a-rogue-like-vampire-survivors-part-15/
- Video Link: https://youtu.be/bbktg7OPyFU?si=Ehm10w5kME4VqD0k
The Thunder Loop is the evolved form of the Lightning Ring. It performs the same function as the Lightning Ring, but after the first strike of lightning, another strike will follow shortly after on the same spot. To create this weapon, we will need to give it: a new Thunder Loop VFX, a new behavior script to change it’s function from the Lightning Ring, and setting up it’s Weapon Data.
1. Setting up a Thunder Loop VFX
[This will be the bulk of what makes the Thunder Loop as the visuals will be more elaborate than the code (Which will only handle the damage)]
- Duplicate the basic “Lightning Ring VFX” Prefab and name it “Thunder Loop VFX”. Rename both the “Shockwave” and “Smoke” to “First Shockwave” and “First Smoke”.
- Create a new gameObject in the Prefab, name it “First Lightning”, and give it the same Particle System as the parent object before disabling every part of the Particle System except for the “Texture Sheet Animation” on the parent object.
- Duplicate the “First” “Shockwave”, “Smoke”, “Lightning”, and rename the new duplicates as “Second”. For each of the “Second” Particle System’s, Change the “Start Delay” from [0] to [1]. This makes sure that a second lightning will always hit a second after the first.
- Copy and Paste the Particle System of the “Soul Eater Aura”‘s “Smaller Aura”. We’ll apply this Particle System onto 2 new Game Objects, “Smaller Aura” and “Bigger Aura”.
Both “Smaller” & “Bigger” Aura:
- Set “Duration” and “Start Lifetime” to [1].
- Change the “Start Color” to Yellow/Orange.
- In Emission: set “Rate Over Time” to [0]. Add a “Burst” of: Time: [0], Count: [1], Cycles: [1], Interval: [1]. Probability: [1].
- Deactivate “Color Over Lifetime”.
- Deactivate “Size Over Lifetime”. This will ensure the “Bigger Aura” remains the same size, while the “Smaller Aura” closes in.
“Bigger Aura”:
- Finally, we’ll create a final Particle System on a new GameObject, “Electric Field”. This will act as a particle spawner within the Aura.
“Electric Field:”
- Set “Duration” and “Start Lifetime” to [0.5]. This will make sure that the Particles will disappear until
- Change “Start Color” to “Random Between Two Colors”, then set the colors to Red & Yellow.
- Set “Max Particles” to [100].
- In Emission: Set “Rate Over Time” to [100].
- In Shape: Change “Shape” to “Sphere”, “Radius” to [4].
- In Renderer: Set the “Material” to “Additive-Particle”, or “Default-Particle” [Part of Unity’s Resources]. (You can choose any fitting particle for this effect)
Final Changes for Everything:
- Ensure all Particle System’s “Sorting Layer ID” is set to “Foreground”.
- Change the Transform Scale to [2] for “Bigger” & “Smaller” “Aura”.
- Change the Transform Scale to [0.5] for “First” & “Second” “Lightning” & “Smoke”.
- Change the Transform Scale to [0.2] for “First” & “Second” “Shockwave”, and “Electric Field”..
2. Writing the Thunder Loop Weapon Script
- Create a new subclass script called “ThunderLoopWeapon”, inheriting from Projectile.cs. This script will be an exact copy of the LightningRingWeapon.cs.
- Create a new Coroutine,
IEnumerator Strike()
. - In
Attack()
, we’ll delete the code within the if statement findingtarget
, usingPickEnemy()
, that calls theDamageArea()
andInstantiate()
‘s the Lightning VFX. We’ll replace the code to callStrike()
. - In
Strike()
, find the target enemy withEnemyStats target = PickEnemy()
to find the position of the enemy and set it as aVector2 strikePosition
for our Thunder Loop attack. - We’ll then call
DamageArea()
to deal damage to the enemies atstrikePosition
. - For the VFX, we’ll set the Instantiated VFX as a
ParticleSystem thunderLoopVFX
. This will allow us to change the angle of the VFX to manipulate the first “Lightning” to strike diagonally. - Instantiate the VFX at the
strikePosition
and at aQuaternion.Euler()
random value angle Z of either [45] or [-45]. - Next we’ll set the
transform.localScale
ofthunderLoopVFX
toGetArea()
. This will scale up the Instantiated VFX by the area of the attack for accurate representation of the damage range. - We’ll then call
WaitForSeconds()
before resetting thethunderLoopVFX
‘sQuaternion.Euler()
to [0,0,0]. This will reset the final lightning to strike straight. - After calling
WaitForSeconds()
for a total of 1 second, we’ll callDamageArea()
again atstrikePosition
.
[Reminder: This code is a duplicate of the LightningRingWeapon.cs code]
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThunderLoopWeapon : ProjectileWeapon { List
allSelectedEnemies = new List (); protected override bool Attack(int attackCount = 1) { ... // Find an enemy in the map to strike with lightning. EnemyStats target = PickEnemy(); if (target) { DamageArea(target.transform.position, GetArea(), GetDamage()); Instantiate(currentStats.hitEffect, target.transform.position, Quaternion.identity);StartCoroutine(Strike()); } ... } ... IEnumerator Strike() { // Find an enemy in the map to strike with lightning. EnemyStats target = PickEnemy(); Vector2 strikePosition = target.transform.position; DamageArea(strikePosition, GetArea(), GetDamage()); float randomAngle = Random.value < 0.5f ? 45f : -45f; ParticleSystem thunderLoopVFX = Instantiate(currentStats.hitEffect, strikePosition, Quaternion.Euler(0,0, randomAngle)); thunderLoopVFX.transform.localScale = new Vector3(GetArea(), GetArea(), GetArea()); yield return new WaitForSeconds(0.9f); thunderLoopVFX.transform.rotation = Quaternion.Euler(0, 0, 0); yield return new WaitForSeconds(0.1f); DamageArea(strikePosition, GetArea(), GetDamage()); } }
3. Creating the Weapon Data and Evolution Data
Thunder Loop Weapon Data
- Create a new scriptable object using “Weapon Data” & select the “Thunder Loop Weapon” Behaviour.
- input the relevant values for the Thunder Loop [Which can be found here: https://vampire-survivors.fandom.com/wiki/Thunder_Loop ].
Lightning Ring/Duplicator Evolution Data
- Select the Lightning Ring & Duplicator Scriptable Object & add a new “Evolution Data” to it.
- Set the “Condition” to “Treasure Chest” & the “Consumes” to “Weapons”, ensuring the weapon only evolves when picking up a chest and will only remove the weapon involved with the evolution.
- Set the “Evolution Level” to [8] for the Lightning Ring and [2] for the Duplicator, before adding the “Catalyst” which selects the other weapon/passive item for the corresponding level of [8] & [2].
- Select the Thunder Loop Scriptable Object as the outcome and set it at level [1]
That concludes how to create the Thunder Loop Weapon.
[Note: I am aware that the “Lightning” Particle effects are sometimes invisible as they spawn in outside of the camera’s range. I will update this post when we are able to fix it.]If you encounter any issues in creating the Thunder Loop, you can submit a forum post to go into detail on your problem for further assistance.
has upvoted this post. -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: