Boaty intelligence

The ocean is dangerous – it’s easy to get lost in the mist and monsters lurk under the surface. Well, they’re supposed to. They need AI in order to bring life to the game and immersiveness to the player. The AI defines how the creatures behave and how they can interact with the player. There are unlimited ways to do this, but all of them might not be boaty enough. Let’s get the boaty intelligence working.

Bringing sprites to life

squid gang
The squid gang. From left to right: Ulf, Henrik and Jerry.

From the concept document of Umibozu, there were already some conclusions to be made regarding the enemy behaviour. The player should have difficulty distinguishing a creature from a pickup unless they are lit by the searchlight. That’s why we decided to implement two versions of the squid; a passive and an aggresive. The aggressive will go straight for the player while the passive doesn’t do anything unless triggered, making it indistinguishable from a pickup when unlit.

The squid life

The squid logic is very simple; kill the player or be killed. Just like the ship, the squids are controlled by applying forces. The movement looks more natural because there is resistance in their movement, just like you would expect from the water’s attributes.

Tracking the player is a requirement for the squids to be seen as threats. The tracking is done by finding the vector that points towards the ship, and then use appropriate forces relative to that vector.

Boaty AI.jpg
The angle θ is found by getting the difference in degrees between the forward vector from the squid and the vector pointing towards the ship.

An angle is calculated so that the squid knows where to turn. The angle can go from -180° to 180° and is used as a multiplier for the torque. With this, the squid is able to home in on the ship. All that is left is to apply forward movement (with Unity’s Rigidbody.AddForce) and the squid will chase the ship.

The boss life

The boss works similarly, as in it tracks the player, but instead of trying to collide with the ship, it tries to keep a distance. The boss uses its tentacles to launch attacks on the ship. Each tentacle runs a state machine, which decides their behavior in the two different states.

boss.PNG
A mockup of the boss.

The two states are idle and attack. In the idle state, the tentacle will surround the ship, but not move too close to it. In the attack state, the tentacle will launch directly for the ship. The boss object (the head) sends instructions to the tentacles which then obeys. There can be a variable amount of tentacles, perhaps scalable with the difficulty.

bossy.gif
It really wants to kill you.

The tentacles are attached with 2D hinge joints. The image above perfectly visualizes the instability with combining lots of rigidbodies, collision boxes, joints and forces. It might need some tweaking before release. Happy hunting!

About Kentaro Hayashida

2017 Game Design