Friday Facts #422 - Tesla Turret

Posted by Earendel, Jarosław on 2024-08-02

Hello,
It's time for those "tesla items" I mentioned in FFF 399.


Tesla turretEarendel

On Fulgora you learn to control lightning, turning it from a threat into electricity. After learning to make more advanced electrical components and mastering the planet's Electromagnetic science pack you are ready for the next stages: Converting electricity back into lightning and unlocking the Tesla turret.


Graphics by Jarosław; Sound effects by Ian

The Tesla turret is an electric turret like the Laser turret. While the Laser turret only takes up a 2x2 area, the Tesla turret is much larger taking up a 4x4 area. The Tesla turret is much more powerful but is also much more power hungry. Not only is the energy per shot higher, but the passive power draw is also significant. It's worth mentioning that we've actually reduced the Laser turret's passive power draw so the two electric turrets have more differences and are better in different situations.

This machine is not simply a tesla coil, technically it's more like a compact particle accelerator that fires a proton or ion beam. Once the primary beam hits a target they are strongly positively charged causing secondary arcs of lightning that can chain to other nearby targets.

This chain lightning effect makes the Tesla turret much better against groups of enemies.

The Tesla turret deals a decent 60 electric damage per second, but damage comparisons are difficult to generalise because some enemies may be weaker to electrical damage, and damage bonuses from technologies make a significant difference. Also, this is just the damage per target, and the lightning can jump to secondary targets 10 times in a chain and they all take the full damage.

As with other turrets, higher quality tiers give the turret more range. The base range is 30, and the range at legendary is 45. The Tesla turret is special in that higher quality also increases the chance for the secondary chain lightning to fork and hit additional targets. The base fork chance per jump is 5% and increases to 30% if legendary.

Damage isn't the only focus of this turret though, it's equally about crowd control. The electrical arcs stun targets, halting their movement for a moment, zapping them back a small amount, and then slowing them slightly for a short time once the stun wears off. This is great for keeping enemies away from your stuff, or even interrupting their attacks if they manage to get close enough. It helps keep enemies clustered, which is great for area effects like flamethrower turrets or explosive rockets. Also locking enemies down to a small area away from your walls is exactly what your flamethrower turrets want.

The turret is more expensive and must be made on Fulgora so, for a while at least, you can't use it everywhere. The synergy with other turrets means that there's still a good incentive to include a few Tesla turrets to back up key locations. Artillery forts are a great early use case because it's an area you know will be attacked and you only need a few Tesla turrets to make a big difference.

You can also unlock a hand held tesla gun, which requires ammo but otherwise functions in a similar way to the tesla turret. The gun version is geared more towards crowd control than other hand-held weapons. Compared to the tesla turret, it can chain for longer and has a higher forking chance.

It may not do as much damage as some of the other weapons, but the extra bounces make is easier for a single gun to control a group of enemies. This is ideal to keep you safe while other sources boost your damage, like cluster grenades, destroyer capsules, and personal lasers.


Game designEarendel

As many of you know, there's a tesla gun in my mod Space Exploration. It's one of the most popular weapons because it's so fun to use.

I always wanted to make a turret version, but there was never a practical way to do it. In the mod a hand held version is fine because at most only a few people would use it at once in multiplayer. If you had more than 50 turrets using the same effect then you'd quickly see it slowing the game down because the mod would need to search for enemies with Lua script for every bounce and that's a slow process.

When I was making the first gameplay prototype for Space Age, it was a "throw things at the wall and see what sticks" sort of time. We knew we were adding an electromagnetism themed planet to the game, so a Tesla turret was a perfect fit. I added a Tesla turret that could be unlocked on the planet, but again the old problem of engine support for features that don't exist yet. At the start, it just had to be a turret that shot the destroyer robot electric beam, but of course there was a plan for it to do much more.

Unlike the rocket turret, which obviously fires rockets, the Tesla turret is more or less a clean slate in terms of its effects. This means it can be more than just damage, and I saw this as a good opportunity to make a turret with synergies: the sort of thing that you might find in a dedicated tower defence game.

A short shocked stun-like effect is a nice pairing with electrical damage so that was added as one of the main non-damage features. Visually it didn't look very impactful though, the enemy just pauses for a moment. Then I tried adding a small push back effect and that made all the difference. By changing their position slightly, it looks like they jump or twitch from the electricity which is perfect. Mechanically it's a nice combination with the stun by hindering their movement even more.


Concept artEarendel

Early experiments (pre version 1)

The concept art for the Tesla turret was tricky because there were a lot of inspirations that I wanted to follow, but they all took the design close to things that needed to be avoided. This made the design process very nuanced and full of pitfalls.

  • The overall structure should be vaguely reminiscent in shape to a nostalgic tesla defence from something Command & Conquer, but it can't be too similar.
  • Between the old beacon design and the new beacon design there was an intermediate version shown in FFF 339. The design didn't work out well for a beacon because it was too visually dominant compared to the machines it surrounded. As some people pointed out at the time, it looked too much like a Tesla turret. I wanted to capture some of this version's look in the new design, but the problem is that our current beacon is also based on the design.
  • It was important that the Tesla turret didn't look too close to the current beacon. They can have some similarities because they're both high voltage systems, but they can't be visually confusing.
  • It needs to convey high voltage and an electrical effect, but it isn't actually an omni-directional tesla coil, it's a proton beam on a rotating turret. This means that it needs a front face, and the face needs to rotate before it can attack (like all our turrets).
  • It should show some relation to the Laser turret to suggest that it's part of the same family, but shouldn't look like a scaled up laser turret.

The design needed a few revisions because Albert, v453000 and I had different opinions on how much of these influences was too much or too little. Also often it wouldn't be obvious that something is too similar to something else from the line art, but it would become apparent in the shaded version. There were a lot of adjustments before getting to version 1, and that didn't really follow a linear process so it's hard to show, but this is as far as I got with version 1 before we decided it was too similar to a beacon and not enough the laser turret.

Concept art version 1. Testing that it works with different player colours.

The final design ended up being version 3. The main intention behind the changes from version 1 to version 3 were:

  • Cover up the hole a bit more.
  • Remove the electric "fence" around the hole.
  • Have the diagonal supports like the laser turret.

Everything is connected though, so in the end only the head ended up staying the same.

At first glance it may look like it's the same but taller, but if you look closer it's like spot the difference but everything is different.

So the final design has:

  • A hint of nostalgia for our retro futuristic look, but not too much.
  • A hint of beacon version 2's face, but not too much.
  • A hint of the beacon's high voltage underground capacitor bank look, but not too much.
  • A hint of the Laser turret in the diagonal supports and green capacitor to the bottom right.
  • And finally, a hint of the tesla coil look in the silhouette, while not actually looking like tesla coil.

Version 3 line art with material assignment.

The last part of the design was the electrical beam itself. The destroyer robot beam is okay for a short distance but doesn't work so well for a long line. The Tesla turret deserves an effect with more punch, but also it's useful for a number of reasons to be able to differentiate the primary proton beam from the secondary bounces. The primary beam is brighter and has a straight laser-like core and electrical arcing on the fringes, whereas the secondary bounces don't have the secondary straight line and are just electrical arcs.

The initial design for the main beam using the existing segments system. Repeating segments are highlighted for clarity.


Final graphics - the electric beam sagaJarosław

When I started working on the Tesla turret, it was a kind of a vacation. Far from the usual complex projects I take on, it was a relaxing little thing. Making most of the model was very straightforward, it went smoothly, and I don't have much to say about that part. That is, until it came to the beam of electricity itself. That's where I found all the complexity I am used to - though the fact that I am capable and willing to over-engineer even the simplest of tasks might have complicated it a tiny little bit.

The turret base has a number of electric arcs that move around it while it is firing, but also when it is idle with power. These arcs always go from one point on the structure to another. We already solved that problem for accumulators, beacons, and the lightning collectors. The arcs on the Tesla turret are a little different but the same approach worked so they weren't too much trouble.

Electric arcs for beam weapons are a different story and proved to be a curious thing to recreate. They have limited structure - they arc (duh) from point A to B, but everything that happens in-between is very chaotic and unpredictable, yet follows a certain rhythm. It's the very kind of structured chaos that is very obvious when done wrong, and as such, hard to replicate. But then there is a more significant complication - the beam would need to be able to hit targets both close to and far away from the turret itself, and as such - should be able to scale.

The obvious starting point was the electric discharge beam already existing in game - a simple yet practical construct. Its ins and outs are very simple - we take a looping animation of a single electric beam split into 6 distinct arcs and then cut it into 6 parts, one arc each. Since the arcs start and end at the same points, we can repeat the segments as many times as we need to reach a necessary length of the beam, and then just slap a little starting and ending effects on both sides. Simple, easy, and - unfortunately - very underwhelming when scaled up to the size of the Tesla turret.

One of the problems - the punchiness of the beam - was somewhat easy to fix. The system was working, it just needed more attention and care to look better at big scale. A few improvements to the process itself - as to limit the loss of sanity - were not a bad idea either. The other problem relates to what I mentioned before - the concept of structured chaos. With the new beam being bigger, reaching further and staying on screen longer, it became obvious the chaos on display is just a simulacrum, with clearly recognizable - and thus, predictable - structure.

To put it simply, in a small beam like for the destroyer capsule the range is low, it usually only repeats once (if at all), and the repetitions are not as obvious because no part of the beam is very distinct. For the Tesla turret the beam is long, it often needs to repeat many times, and each segment is more extravagant so repetitions are more obvious. Every segment of the beam is locked to the same timing so that it always matches up with the segment before it, but that means if that part of the beam jumps to the left then exactly the same thing happens at multiple points along the beam at exactly the same time and looks very unnatural. Something needed to change, so Earendel, Vaclav and I started brainstorming (with me mostly just storming), and we came up with two crucial improvements to the system.

For the first one, each of the arc-segments became twice as long without changing the spacing - that meant huge portions overlapped. With the central proton beam working as a base or grounding, the arcs could go much crazier and we didn't need to care about how they attach one to another. Furthermore, this approach made the separation into segments look more natural and less constructed. The real deal though was the approach to randomization. An obvious improvement you could think of would be to use randomised segments instead of using them in order from first to sixth and repeating. Yet, if there is one thing I've learned working on space platform borders and the platform hub - it is that RNG Gods do exist, and they suffer not an artist, loathe a designer! Nothing kills the feeling of natural chaos as surely as a few copies of the same lightning repeated at uniform offsets.

A different approach was needed - and Earendel provided a brilliant one. Instead of randomising the order of the segments we use, we randomise the offset of the animation. Since each animation loops into itself, starting it at the "end" is not a problem, and the chaotic nature of an electric beam means that often just a few frames of an offset is sufficient to differentiate it from other instances.

With all that out of the way the last thing remaining was to roll my sleeves up and get to the technical part.

The system we used for electricity before is a very simple one. It's based off of a very simple ribbon shape that is then displaced using various random maps. If you do not know 3D graphics, you can think of the displacement as the way waves would move a ribbon floating on a lake. Though in our case, instead of just waves, we also have a miniature storm displacing the ribbon in a very chaotic manner, creating a visual not unlike an arc of electricity. The shape of the ribbon can be further adjusted using hooks, special objects that can "pinch and move" the centre of the arc around - those will become very important in the next step.

What we have now is what is used in existing and new buildings to render electricity - but for something more glorious, like a Tesla turret, we need to go much further. Next step would be to increase the violent jumps typical to electric arcs. We could use the hooks to do that - but that would require tons of manual effort, as trying to recreate chaos manually is typically quite tricky and tedious. Instead, I decided to create a new system of deformations, which I named in my usual fashion: the Insanity Drivers.

The way these work is very simple - I have a set of randomly rotating objects (rotators), and then another set of objects that reads that rotation and turns it into movement (drivers). The gimmick rests on the way 3D graphics perceive rotation - any rotation beyond 360° "resets" to zero and continues from there. That means if a rotator spins on one axis for 2 full rotations, an attached driver will then move from point A to B during the first rotation, then "teleport" back to A and move to B again. Now, imagine the same, but with rotators spinning wildly on all 3 axes in a random manner - or better yet, watch it in action below!

Now it's a very simple manner to attach our hooks - controlling the ribbon - to the drivers. That produces adequate results, though I did have to fine tune them here and there by manually adjusting the position of the hooks. I thought of that step as merely a slight adjustment, but it turned out to be much more important - that "human intervention" into the randomised chaos managed to place is somewhere in-between fully procedural and fully manual approaches, so exactly where I wanted it at.

As it is now, the arcs stay attached to the central beam, no matter how violently the Insanity Drivers pushed them away. I wanted to address that, and "cut" the arcs in certain places, giving the illusion of the arcs tearing away from the beam. It would be a lot of work to do it exactly that way though - moving the end of the arc away and back would affect a lot of other things already in place. I decided to look for a little "cheat" then - and that cheat was to selectively narrow the ribbon from the end to a point it "disappears". Technically, the arc was still going from A to B, but visually it was violently ripping apart from the beam due to the amount of power it carried.

With the main arcs in place, I wanted to reuse the system to create further, smaller arcs. I was very happy with the shrinking trick used before, and wanted to use a similar effect with the smaller lightning... just on a bigger scale. The solution I came up with was to use a method called Backface Culling - which, in layman's terms, means that I made the back side of the ribbon invisible. Since the ribbon is thrown around by the miniature storm of the displacement, it twists and rotates a lot - and if we only draw the front side of it, it adds up to a very nice supportive effect!

At that point I was pretty happy with those effects, but one thing was standing out to me - the combined effect was very dynamic and aggressive, yet it lacked directionality. It seemed to just "sit there" instead of delivering a concentrated dosage of freedom electricity straight to its target. That is why I ended up adding a second layer of secondary arcs, this time travelling at high speed toward the end of the beam. Even though those are miniscule and hard to spot even when you know what to look for, it was enough to trick the brain into perceiving the subtle movements without it being too obvious and overwhelming.

With all of these systems in place, I wanted just a single last piece of the puzzle to fall in place - the lightning forks, splitting away from more pronounced arcs. Remember how I mentioned adjusting the arc to travel to a different point B was going to be a lot of work? Well, so it was, since those lightnings were added by hand and adjusted frame-by-frame to fit the rest of the animation. Even with just a few of those, the amount of moving elements grew very quickly and I needed to seek ways to preserve my sanity by automating my workspace itself - by making sure certain elements are drawn or hidden only when they are necessary.

You can see a bit of that in action below.


The places where the lightning would show up are simplified, and the shape of the lightning shows up only when it is animated and visible.

Another point worth mentioning is how distinct those shapes become - and distinct shapes are a bane when working with anything repeating (which we come against a lot here). With distinct shapes and movements it's very easy to lock onto the pattern and see the fakery - yet despite that, due to the way we randomise starting frames of every segment, that is not a problem in our case!

With all these parts put together, we can see the final result of the beam.

All that was left to do was:

  • Prepare the special effects for the Tesla turret's counterpart, muzzle flash, and the hit effect.
  • Scale down and adjust the beam to serve as the secondary chain as well.
  • Post-process everything.

Then we put it all together in-game and... well, I hope you will enjoy the possibility for throwing a sick rave party!


Biters trying to sneak into the club.


ConclusionEarendel

Depending on the order you visit the new planets, and how much you rush to the end, the Tesla turret is one of the things that you might never use and still complete Space Age. With our focus on removing things that aren't necessary, it could have been removed from the game, but it wasn't. It stuck around because it does have a clear role, it's always useful for the rest of the game if you make use of it, and especially useful if Fulgora is your first planet. Mainly though, it's still here because it's just so damn cool.


As always, zap your thoughts to the usual paces.