Intelligent fish

In our game you play as an exploration robot that look at fish, and later avoid getting bit by meaner fish.

screenshot.png

Since you can’t kill any fish in the game, it’s important that they are interesting to interact with and swim around like actual fish. They are state machines, which makes it easy for us to reuse behaviors and organize logic. The fish use a bunch of trigger hitboxes to sense their surroundings.

fish sensors.png
An observant fish

When something enters the sight trigger, the fish can see it. If the fish spot something suspicious (e.g. the player or a hungry fish) it switches state. The intimate trigger does the same thing, but for more acute situations. For example, this fish would flee if the player enters the intimate zone.

To be able to tinker with values and edit the states, they are added as components to the fish. Then they are dragged to the state machine, which disables all states except for the active one.

fish fsm.png
The proximity field corresponds to the vision. This could be renamed for better communication.

As you can see from the image, the fish doesn’t need to react to every situation. This state machine is from the fish in the pictures above, and it doesn’t do anything when it sees the player. Other fish could slowly move towards the player, or subtly avoid them.

Homes and fish points

We want to have some control of the placements of the fish. These are two schools of fish placed on the map.

schools of fish.png

To force the fish to stay at the same location, they are bound to a ”fish point” (or fish node, but point sounds more military).

fish point alpha.png
Fish point alpha

The fish are children to the point, and they will know if they are outside of it. If the fish are in their idle state, they will make sure to stay close to their point. But what if the fish are chased around by the player and swim so far away that they can’t see their point anymore?

sad fish.png
The blue arrow is the correct way to the point, but the poor fish is too stupid too see.

The fish is breaking his head trying to go back to the fish point! We could add path finding, but it’s too much work. Instead, we move the fish point to the new location.

independent fish.png
A happy independent fish

Right now when a fish move from it’s original point, it creates a whole new fish point just for itself. This could be changed to first look for any fish points close by, but I chose this for now because it was fast to implement. The other solution could also potentially endanger the poor fish, if it mistakenly chose a shark nest for its home!

And that wraps up the fish AI for now. Next up is adding chomp hitboxes to the angry fish and make sure that they can kill things.

About Erik Säll

2016 Programming