Some weeks, it's hard to think of what to build next.
You catch up on email, start a new todo list, watch twenty-two vaguely relevant Youtube videos, fantasize about a total rewrite - and somehow you're still not inspired.
But, this week wasn't like that! I knew I needed a Barrier spell, and I just needed to build it.
The Concept
Continuing the theme of, err, being inspired by Magicka, I wanted summoning Earth + Shield to create an impassable barrier: 1
Conceptually, this is pretty straightforward, right? Just make a bunch of atoms slide up from the earth and we're done!
Moving Atoms
But... in my homegrown game engine, to move atoms as a group, they have to be in a moving body - linked to the rigid body physics engine.
And as far as the physics engine is concerned, a body must be one of two types: 2
- Dynamic, like barrels and rockets - these are moved by the physics engine in response to collisions (and forces I apply).
- Kinematic, like bullets and characters - these are moved by my logic directly.
I figured dynamic bodies wouldn't work well for this because rock barriers shouldn't be moveable by any other objects, but maybe we just try it?
But kinematic bodies come with a big caveat: they will do whatever I tell them to do.
- Move through a wall? No problem.
- Push a barrel through a wall too, making it glitch out? Sure!
- Pin a player's character so they can't move? With pleasure!
So you're meant to use them very carefully: moving platforms in a level editor, or bullets that disappear when they hit things - that sort of thing.
Letting a player place a moving kinematic body pretty much wherever they want? In the presence of other (dynamic) physics objects?
That's asking for trouble.
Handling Dynamic Bodies
Luckily, I realized that in this game there are only two types of dynamic physics objects: 3
- Physics objects that explode.
- Physics objects that don't matter.
So, I figured out an easy fix: spikes make explosive things explode instantly.
And for things that don't matter, like corpse ragdolls, well, I just turn off collisions between spikes and those things.
Will I ever need a physics object that can't explode but still matters? Hopefully not!
Handling Characters
Characters, like players and enemies, are supposed to be blocked by the spike.
But since you can place a spike anywhere, you can also trap players and enemies inside spikes, so they try to stop that:
As a bonus, it makes characters unable to stand still on the edge of the spikes, which makes enemies less adept at jumping over them.
Destroying Spikes
One thing I got "for free" from my engine was that the spikes were destructible from the get-go:
Except, well, spike pieces are not meant to float in mid-air like that. 4
Some really tedious coding later, it worked a bit better:
It might be cool to have those other spike pieces dissolve into sand once the spell ends,5 but I haven't implemented that.
Spiking Spots
Spikes slide upwards as intended, but in some spots the sliding looks horrible:
A neater solution might be to grow the spike as it slides up, and stop sliding when it hits a ceiling. 6
Lastly, the logic for where to place the spike also needs a bit of work still - it finds the lowest point in front of you, but sometimes that's on a platform way below you. 7
Elemental Effects
As always, each element you mix into (or repeat in) your spell adds an effect:
But I'm still deciding what mixing more Earth elements into a spike spell should do:
- Create more spikes?
- Make the spike tougher or last longer? (like Magicka)
- Change the size of spikes?
(...all of the above?)
Spiky web build
Go summon some spiky barriers: press E, 3, then some more keys of your choice, then left click:
Here is Magicka 2's barrier spell.
Magicka 1's barrier spell is actually more impressive in my opinion, but I couldn't find a nice video of it and I'm out of time to make my own recording!
Okay technically there's a third type, "static", which means the body is not expected to move ever. It's kind of pointless, as far as I can tell? You can get that same behavior by making a freestanding collider that isn't attached to any body.
It sounds like a joke, but I think this generalization actually holds for lots of games?
Consider how player characters can throw physical objects at non-player characters in Skyrim and they don't even blink.
Can you guess why they float?
Answer: the spike is a kinematic body, and the logic that detects breaks in bodies (when atoms get destroyed) makes the new body be kinematic too.
The controlling spike logic doesn't realize the spike split, so it just leaves it.
Especially since I just realized that such spike pieces probably get glitched out by a new spike that spawns under them. Hmm...
For just fixing the rendering portion, it would be possible to use a stencil.
But it's not a pure rendering problem - right now, the spike actually exists below the platform for a couple frames, and could conceivably interfere with things there.
So should the spike always be on the same platform as you? But what if you're on the edge and there's no space? And what if you're mid-air when you cast it?