Making a child’s behaviour

We are currently making a game about a moth trying to rescue her children during a dark night, therfore the the children are a very important part of the game. The main objective is to find them in and bring them to safety. One of our main goals is to create a bond between the player and the children. The player should feel protective of the children and loss upon losing a child. To create those feelings I will attempt to make the children feel alive. The tools I use to create their lifelike behaviour and the connection to the player are movement, light and sound. At this time I have made 3 different states and movement for these states.

Lost state

At the start of a new game, the children have not yet been found by the player and are therefore in the Lost state. If they were completely still in this state, they wouldn’t feel alive. They are small moths who don’t really know where they are or how to survive on their own, therefore they will stay relatively put. I have made so that they can move around freely within a small radius from their starting position. Every few seconds the child changes its direction and speed randomly and if the child is on its way outside the radius it turns back toward the center of its movement restrictions.

I have made a timer that counts down every frame to determine when the child changes its direction. When the timer hits zero, the child’s new movement direction is determined by a randomly made angle and a random float between one and three is made as a multiplier for the speed. The movement speed is created by adding a force to its rigid body 60 times per second. This could potentially make the child accelerate forever, if there was nothing to slow it down, but to counter that acceleration I am using the linear drag already built for Rigidbody 2D in Unity.

Following state

If the player is close enough, the child’s state will change to the Following state. In this state the child follows the player blindly, but even though it is moving faster than it does in its lost state it is still not as fast as the player. If the player flies too far ahead of the child the child will go back to the lost state, but switch out the starting position for its current position.

follow_state

Idle state

If the child is close enough to its mother to feel safe, it dares to move around a bit, but never far. It will slow down and very much like in the lost state, it will move around freely inside a radius from the player’s position. As soon the player moves away from a child, so that it is outside its idle movement radius, it will switch back to the following state.

idle_state

Lights and sound

To make the children stand out from other creatures in the dark my teammate Rishi gave them a light source that is dependent on the distance to the player. If they are outside a certain radius from the player, this light source will not be there.

The children will later be able to make specific sounds depending on the the state they are in. How often they make these sounds will also be determined by the state, but the volume will be determined by the distance to the player. To make the sounds even more significant I want tie a light source to the same script. When they make a sound the light source will trigger on them and you can make out where they are.

About Sebastian Wallin

2016 Programming