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:

angus.png
Cute couple. (The head on the top is the male).
sad moray eel.png
A sleep deprived moray eel. Finalized art.

Anglerfish

We 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.

stalker.png
The concept for the stalking behavior.

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 eel

The 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).

murana.png
Eel behavior concept.

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.

fish-fsm
A simple fish flowchart

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.

moray fsm.png
The eel flowchart.

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.

tethered attack.png
Eel attack state

Just like the fish state machine, the states are added as components and switched on and off by a state machine component.

ifsm.png
Short and sweet!
fish fsm editor.png
The fish state machine.

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.

eel editor.png
The eel in the editor.

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.

anglerfish.png
Did you know the male anglerfish slowly melts into the body of the female until he is reduced to a pair of testicles?

3 reaktioner till “More enemies”

  1. Hi Programmerik.

    This is I, the Designer of time.

    I can see that you read my comment on Påls blog, and you did listen on my advice about adding more enemies. I think it is a wise decision you made and hope that more people listen to me as you do.

    If you need to contact me you know you can always reach me on my g-mail. thedesigneroftime@gmail.com.

    / Yours truly, the Designer of time.

    Gilla

  2. Hello! Very interesting post, lots of good information.

    I’ve personally dabbled in the arts of state machines in unity but never really got a good one working that used several different scripts.
    Either way, it was interesting to read about the fish you were working on, their behaviour and to see the different requirements for the different fish. You talked about the unity animator and how that could be used as a state machine which is good. As some might not have known that, letting them know that there are other options for doing things. Flowcharts were a nice touch ad allowed me as a reader to easily follow the general idea.

    As a coder, maybe I would have liked to see some example code? But at the same time, the general structure of the post and the charts and pictures allowed me to easily understand everything without looking at the actual code so. Goldstar for that.

    Entertaining, explanatory and educational. Very nice!

    Gilla

Lämna en kommentar