Wizard Dev Log 4, Lightning Bolt


Behold! A lightning bolt, the bane of my existence!

I hate this thing. My code for it is shit, and I don’t know how to fix it. Right now, the main problem is the particle effects because the Niagara System is insane. Let's start with the spawning code. 

There’s several parts of this code that only work from lots of testing. This is a slightly old screenshot, so some numbers have been adjusted. It starts with a line trace for static objects, piercing anything like enemies that would get in the way. This leads to a branch based on if the trace hit anything or not. Assuming it hits, two main variables need to be made, the transform location and transform scale. The shell (i call it the shell and the bolt interchangeably, because it’s both the spawner for the lightning bolt particles and the lightning bolt itself) must span exactly the distance from the player to the hit location, with a little wiggle room so it doesn’t spawn directly inside the camera, which required a lot of trial and error to tune. The transform location is easy to calculate, just averaging the hit location and start, which puts the shell exactly in the middle of the two. Imma be real, idk why the next part works. It involves using the length between the start and hit locations to adjust the shell’s length, but it has to be multiplied by 0.095 to actually work. Why? Idk, but it’s consistent. 

The second arm of the branch controls what happens when you don’t hit anything. It’s much simpler, as you can assume what the length of the shell must be without calculations. With the lightning bolt spawned, we can look at its own code. It sits midair for a while before exploding, like if Ultrakill’s rail cannon was under the freezeframe’s effect. The shell has an outer glow effect that shrinks with time, telegraphing almost exactly when it’s going to explode. Every tick, it decreases in size by a set amount. This effect was surprisingly temperamental. If the shell is too long, it will be basically placed on a low frame rate, flickering from full sized to half and then gone. If I had a choice, I would have made the trace 2000 units instead of 1500, but oh well. 

Time for damage

After a second, a multi sphere trace moves from one end of the bolt to the other. End 1 and End 2 are just invisible little points on each side, only used for this. The trace only bothers to hit a few object types for simplicity. 

After checking to make sure that an impacted actor is not the player and hasn’t already taken damage from this bolt, 120 damage is dealt to the actor before it is added to the previously hit array. Then there’s a Switch on Int, like in the fireball, but this one decides if the hit actor is a projectile of a certain class and in the future will likely do an additional action if so. Like a rail coin or extra damage or whatever. For now, it just says hello if it hits a fireball. 

The last problem is one inherited from an asset pack I got for free a while ago. It’s a very nice lightning bolt particle effect, but it has one problem. It will only ever strike down from above, meaning I can’t make it travel across the bolt’s path. I’m trying to make it work, but damn am I stupid. 

Leave a comment

Log in with itch.io to leave a comment.