UNITY: artificial intelligence in a grid-based action game

This is the first post in a series of theoretical articles about the development of the game Westy West, a tile-based action game that resembles Crossy Road. I am sharing a general idea of how the characters’ Artificial Intelligence works. I will divide this article into six parts: Enemies, Innocent Civilians, Police Officers, Wanted Bandits, Decorative Characters, Defensive Animals, and Harmless Animals.

1.0 Inimigos – General Description

The enemies in Westy West are identified by their black clothing. The appearance, health, weapons, and means of transportation of the enemies are randomized at the beginning of each game level. They can wander around the scenery, dodge obstacles, chase the player, and attack with melee and ranged weapons of varying ranges and power.

1.1 Enemies – Mood States

Enemies act according to two mood states: calm and angry. The “calm” state is the initial state of all enemies and occurs when they have not yet seen the player. The “angry” state occurs after the enemy spots the player and is characterized by a surprise sound and an emoji balloon above the enemy’s head.

bandido-alerta
Enemy spotting the player

1.2 Enemies – Movement

Enemies move at intervals. The length of this interval depends on a random variable, the minimum and maximum values of which depend on the player’s level. The more advanced the player is, the shorter the intervals between the enemies’ movements, making them faster but still within an acceptable limit that does not ruin the game experience.

The enemy’s mood state also influences its movement. During the “calm” state, the character walks around the scenery in random directions and may even stand still or walk in circles. In the “angry” state, the enemy constantly moves toward the player to attack.

1.3 Enemies – Attack

Enemy attacks are simple; they attack the player whenever they are within the range of their weapon, which can be 3 (pistol), 2 (shotgun), or 1 (melee weapon).

bandido-melee
Bandit trying to attack the player with a hammer

The attack frequency (“fire rate”) depends on the same interval used for movement so that the enemy never moves and attacks simultaneously. This ensures fairness for the player, who can only perform one action at a time (move or shoot) and avoids visual confusion in a grid-based movement game such as Westy West. (we tested this)

1.4 Enemies – Goofiness

Humor is a key aspect of Westy West, characterized by the enemies’ stupidity. While it is necessary to impose difficulty on the player, the enemies’ stupidity creates funny scenes, such as enemies accidentally hitting each other or destroying objects in the scenery between them and the player.

galinha
Chicken getting in the line of fire and dying

This is pretty simple: the enemy ALWAYS shoots when the player is within the range of their weapon, without evaluating if there is an obstacle or character in the way. Thus, before hitting the player, the enemy may accidentally destroy objects or injure allies and innocent civilians.

The only enemies incapable of making these mistakes are those using melee weapons because they need to be next to the player to attack, as their weapons have only a range of 1.

This creates unexpected and funny situations and is entirely intentional.

2.0 Innocent Civilians

Civilians are NPCs (non-playable characters) that only wander through the cities in the game. They wear colorful clothes and ignore the player’s presence unless attacked by the player.

2.1 Innocent Civilians – Movement

The movement of innocent civilians is identical to that of the enemies. (item 1.2 of the article)

2.2 Innocent Civilians – Panic

Civilians can panic upon hearing a gunshot. In this case, they raise their arms and run through the scenery.

civis-panico
Civilians raising their arms in panic

2.3 Innocent Civilians – Violent Reaction

Some civilians have weapons and start chasing the player if attacked. When attacked by the player, they behave like an angry enemy (as described in items 1.1, 1.2, and 1.3 of the article).

3.0 Police Officers

Police officers appear in the game if the player harms animals or innocent civilians. Thus, their purpose is to suppress any unethical behavior by the player, as the game does not aim to encourage gratuitous violence. They behave like enemies (as described in chapter 1 of the article).

policiais-ataque
Police attacking the player

4.0 Wanted Criminals

Wanted bandits are those on the “Wanted” posters that appear when clicking the button in the top left corner of the screen or interacting with the poster present at the game’s Checkpoints.

These bandits look like innocent civilians, wearing the clothes shown on the wanted posters, and can be discovered by the player.

procurado
Wanted Criminal being discovered and reacting

Wanted bandits wander around the map like a calm enemy (as described in item 1.2 of this article) and do not attack the player unless attacked first. If the player attacks them, the wanted bandits draw a weapon and start shooting at the player (as described in item 1.3 of this article).

5.0 Decorative Characters

Decorative characters include Pianists, Dancers, and the Mexican Band. Pianists do nothing but play the piano. Dancers dance while the pianist plays and stop if the pianist dies.

dancarinas
Dancers stopping after the pianist’s death

The Mexican Band spends all their time playing and looking at the player. If a band member is killed, the others continue playing their instruments as if nothing happened, and the music continues with the absence (sound) of the destroyed instrument.

bandafinal
Band playing with one less member and turning towards the player

6.0 Defensive Animals

Defensive animals include snakes and horses, which stay in specific spots on the map and indiscriminately attack any character who stays too close for too long, whether it is the player-controlled character or not.

inimigo-coice
Character being fatally kicked

I call these animals “defensive” because, even in the real world, these animals attack only to defend themselves in situations where they feel threatened. It is incorrect to say “horse attack” or “snake attack,” which is why incidents with venomous animals are called “accidents” and not “attacks.”

These events instantly kill any character.

7.0 Harmless Animals

Harmless animals include chickens and coyotes, which only walk around the scenery like a calm enemy (explained in items 1.1 and 1.2 of the article), making noise and pooping in the scenery.

Conclusion

Westy West is much more complex than it seems, and Artificial Intelligence is just one of the many aspects of the game that took several days to refine. I am proud to have reached this level of work without ever taking a programming course, and I am happy to share this knowledge with new programmers (and experienced ones too). I hope to write more articles about this game in the future.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *