Step aside, Rain World! Vatnsmyrkr is here with Fish AI™ that will blow your CoD away!
UPDATE 81
Well, not really.
Rain World is fantastic and I'm just starting out with this kind of stuff, tho I've dabbled before. But they gave me
some neat tips on AI. And I read up a bit elsewhere, just to get a basic idea on how to tackle the issue, because I was about to implement something that can only be summarised like this:
FISH AI™Well, jellyfish. Have a gander:
Finding their way around the submarine to get to the glowing magnet, which attracts 'em. And when the submarine drives through the group, the poor jellies are flung aside! Mean.
What's this for?Like I told you at the end of
the last update, I was going to be working on something that would take the game even closer to the concept drawing mentioned recently when I realised that the game was starting to look like it. That drawing had blue, bioluminescent jellyfish in it! And here we are.
Since the jellyfish in the GIF don't yet look all too much like those in the drawing, but are just fairly static placeholders, here's a reminder, since the drawing has fallen back at least a page now:
At the time of drawing this, they had little purpose but looking nice and fulfilling the environment, and it was just days ago that I finally connected the dots and found some use for them in a segment that had itself been planned for a very long time. I did in fact connect at least two other old ideas to this segment, finally giving some purpose to it all.
All I'll say for now is that
sometimes one will need the aid of the glowing jellyfish in exceptional darkness.
And they'll look beautiful congregating around the submarine, of course.How does AI work in the engine?Like I said, I got some tips from RW people, and I read up a bit myself, on general principles on AI. And I sort of ignored a lot of them to some extent, at least for now, but I might need those concepts later.
I started working on a little AI system for the engine. Planned it out a few times on paper before I had a good foundation to work from and then it unsurprisingly changed a bunch anyway as I was implementing it. I realised I could solve certain things by using already existing systems in the engine, and a few things not originally planned were added along the way.
There are four classes for now.
• AI system and AI groupsIn practice, a singleton. Each level/scene has one of these accessible. In it AI's may be registered into groups that may want to talk to each other and so on. For this particular use, I've created a group called
jellyfish and registered all of the jellyfish objects in there.
• AIThe main class, of course. It's a component that can be added to objects. States can be registered and assigned priorities, tho priorities don't do anything yet, but the idea is that in the case of conflicting possible actions for an AI to take, the one with the highest priority will be chosen. It sends an update event to the parent each frame there is a state to be handled, and allows for custom implementations there — no states actually exist or do anything in the engine by default; that's up to the user to implement.
• AI triggerThis is also a component. It gets put somewhere and an AI can register it. Each frame, the AI will ask the trigger what to do. In this case — for now — the submarine's magnet has a trigger that tells the jellyfish AI to start following the submarine if close enough, tho that's not how it's really supposed to work in the end. Rather, it's supposed to attract them only when glowing.
Worth mentioning is that the jellyfish code is in an AS script, and not in C++! Quite neat.
What's missing?For now, the jellyfish have only two states:
wander and
follow. The former currently does nothing, so they just stay still, but they're supposed to be moving around and doing their own thing in this state. The latter is of course the one shown in the GIF.
There will be more states, however. They will sometimes
flee. Sure, real jellyfish might not exactly be an animal with such instincts, but it's more that they're getting disrupted by something and start moving elsewhere. The action of speedy animals itself will also fling the poor, lightweight critters away as seen at the end of the GIF.
There's also an element missing to this section: something to cause this fleeing. More on that later, but you can
check my Twitter out if you want a hint.
And of course, at some point, proper graphics need to be added to the jellyfish.