The next step of making enemies awesome is making them made of parts, i.e. modular. Let me try to expand my animation and sprite framework to support multiple sprites at the same time. For example, I will add mob head sprites (second column):

In order to have multiple sprites per mob, I need to restructure the whole pipeline. World objects need to have multiple sprite renderers and the animator setup needs to specify multiple sprite entries:

I am also keeping a default entry, which is what the animator uses unless there is an overriding value. This keeps it simpler for me to modify. Anyway, this now works:

Of course, none of it is positioned correctly as all sprites pivot to the base. So I need to re-position the sprites. I can define the default position for each:

And the individual animation entries can offset it:

And this looks like this with values:

Of course, the dead mob props still don’t do this:

If I am going to break the mobs up in parts, I want my props separate too. But the enemies can only spawn one prop, so I need to make separate death setup asset and fill it out with entries for each prop it should create:

This means I need a prop for each body asset:

The number of my assets is sky-rocketing. This does, however, allow me a great deal of customization for each part. Imagine an explosion sending all robot heads flying but their bodies move only a little because there are different mass settings for those entities. Or something. Anyway, when the mobs die now, they transform into multiple parts:

The problem here is that the mob’s “head” is technically above ground. But I don’t have and won’t implement the third axis to my world. So I will just manually offset the sprite. To do that I needs to know where it was, which means looking up the animator’s data :

And this let’s me apply the same offsets to both props as the mob had:

Of course, a floating head is just weird, so I want to make it “drop”. I will simulate basic gravity for its Y offset and have it drop to the ground level, i.e. no offset. This is purely math-based and nothing in the world knows or cares about this extra vertical offset. So like this:

Now I can also specify a random angle force applied to the death prop, as in an explosion:

This looks very basic with just 2 parts, but should look pretty good with multiple parts and potential variations. In any case, the framework is now there and it’s a matter of making sprites and filling out assets and then tweaking the parameters.

Now that I have added myself a bunch of extra work, let’s see if I can trim some extra work. For example, do I really need different sprites?

I can still keep all the animation logic, but I don’t necessarily need to have custom sprites. If I can make modular enemies, then I can animate a lot procedurally. For example, adding legs to enemies is fairly straight-forward and the defaults handle pretty much all cases:

In fact, now that my props are single-sprited again, I can get rid of the need for an animator for every prop and go back to using the mob’s animator, since I will have multiple props for each part. I just need to specify which animation state/step and which sprite to use:

And it works out okay. I mean I will have to have some art direction here, otherwise it will be a giant mess:

But it’s still cool and busy and looks like a real battle took place.

Now, I don’t want to script enemy part explosion details, but I do need to restrict it a bit, mainly the direction in which the props randomly  travel, e.g., the left leg shouldn’t fly right or something. I am already specifying the force, so I might as well specify the random angle:

And a final touch is to actually rotate the sprite as if it “falls down”, which I can specify along the forces:

And it works fine:

It all works fiiiiine:

In fact, let’s give enemies their own weapon “skins”:

I think that about covers modular enemies. I’m sure I will improve this and add features, but — as always — the framework is now there.

Related Posts

MicroRogue DevDiary #33 – Modular enemies
Tagged on:             

Leave a Reply

Your email address will not be published. Required fields are marked *