Monday, August 10, 2015

How enemies and AI work in Twelve

The AI in Twelve is a crucial part of the game, perhaps one of the most important aspects beyond the very ship you control. These non player characters are programmed to be either ally or enemy to the player, however all AI behaves identically in Twelve.

    (Pictured here is the player [purple] being attacked by enemy AI [blue] in their sector)

In this game there's an emphasis on equality between the player ship and the AI ships, which means they had to appear to be as powerful as the player. Now of course there are differences, notably the player's HP is greater than the AI, that was necessary for the player to be able to play and survive for longer periods of time than the enemies. Which lends to the fun of the game and the conquest of other factions. 

Territory is divided by 12 different factions, each controlling their own bit of space. The sectors at the edge of borders are potential targets for invasion, this will occur every 6 seconds where one of these sectors will be invaded and taken over by it's rivaling faction. 


The image above represents the possibilities for the middle sector to be invaded, it is only affected by the adjacent sectors and itself. The percentages in the image determine the possibility of the middle sector to be changed or to remain to that colour. Since there are two blue sectors adjacent, there's a 20% chance this middle sector is invaded by blue. However there are two red sectors adjacent aswell as the middle sector being red, which adds up to 80% chance of the sector remaining under red's control. All this allows for the universe to function and simulates the constant warfare between the factions. 


AI are programmed to constantly scan ahead and detect the nearest object, they then calculate and adjust their trajectory to avoid collision with said object. To shoot, they will pick a random target that is not of their own faction and pursue it until that ship dies or they do, if no targets are found they wander aimlessly in their original spawn area. AI will spawn randomly near the player offscreen, and de-spawn when too far from the player. The game makes sure there is always the right amount of AI that spawns by comparing the amount of currently present AI and spawning new ones when the player moves around. They will most likely be the same colour as the sector you're in, however some will spawn as surrounding sectors' colours. Similar to how territorial invasion works (as explained above), the colour of a spawned AI depends on the current and surrounding sectors, with possibilities varying by amount of a certain colour. 



AI will generally try to avoid the player and any other ships, they will shoot at their chosen target until they get too close, then they will turn back around to a further distance before beggining to shoot once more. They will begin to flee when their target chases them to avoid collision and being shot, but return to shoot them once their target faces another direction. When in a sector that belongs to the player's faction, also known as a "safe zone", the AI that spawn will most likely be of the player's faction. Which means they will be allies. Allies will act exactly the same as enemy AI except they will not target the player and cannot hurt the player by shooting. They'll instead aim for enemy AI, and in the end aid the player significantly by both being an alternate target and disposing of enemies aswell. 

The AI utilize a very precise algorithm which takes into account it's target's speed and the speed of it's laser to ensure a direct hit. That algorithm is mostly comprised of linear algebra, a bunch of boring numbers and lines that were bred from the blood, sweat, and tears of the poor, poor programmer. 

Ultimately, the AI is programmed to shoot enemies while being smart enough to avoid collisions. This makes them a threat and even challenging for the player to defeat, but still useful when the AI is allied to the player. The collision avoidance, targetting system and territorial invasion of AI all contribute to the challenge of Twelve, and allow the player to feel the true conflict in the universe while capturing territory of their own. 

We hope to have you explore Twelve's expansive universe soon. 

-Brendan

No comments:

Post a Comment