More enemies
|
As we move into production the focus turns to producing a bunch of fish. This week I implemented the behavior for these baddies: ![]() ![]() AnglerfishWe wanted the anglerfish to feel creepy. When she notices the player (or another fish) she will stalk them by keeping herself within a set distance. ![]() She doesn’t actively try to attack the player, just stays in close proximity. Spooky! The fish is using the same state machine as in my first blogpost, which made the implementation quick. Most of the behavior is reused but modified; for example, the idle state is a slower version of the peaceful fish. Moray eelThe eel was a bit trickier. Since it doesn’t swim around and share the same traits as the other fish, it didn’t make sense to use the same structure as the other fish (The fish are in acute need of refactoring, but I will put off this for after production). ![]() The biggest reason for redoing the structure was the flowchart of the state machines. The fish state machine switches states when reacting to different things. When the states are done they always revert to a default state. ![]() The moray is simpler, but uses another type of flowchart. The states don’t revert to a default state when they are done, but rather move to the next in the line. ![]() I’ve heard the Animator can be used as a state machine in Unity, which would be ideal, but I decided not to do this because of time pressure (it’s risky to research OK). Instead I made something similar, where each state has a tag and a way to switch to another state via tags. ![]() Just like the fish state machine, the states are added as components and switched on and off by a state machine component. ![]() ![]() The flowchart is not as visual as the Animator, but I don’t wanna make an editor OK? The fish state machine (to the right) had to get the states dragged into finite slots which were switched between according to a set logic. The new state machine only needs the starting (aka default) state and accesses the states automatically since it doesn’t need to know the states’ context. The states themselves holds the information on which state to move to next. The finished eel uses a trigger collider to react to prey swimming by, which activates the attack state. ![]() Let’s hope I find a smooth way to implement the new state machine (or adapt it) for the old fishes, since it’s so much cleaner. ![]() |










