Artificial intelligence for games in Unity

I'm creating a game in unity, and I'm wanting to do some bosses, only for this I need to study artificial intelligence, and I do not have the slightest idea where to start, I looked for books but they are very scarce, and those that I found or are not in C#(only language that I know besides Kotlin) or else(more common) has no relation to games, where I can get Study sources? The Boss style I want to design is in the style of the game Hollow Knight, if you guys can you take a look at the first boss, the "False Knight" I would appreciate it very much! Recommend places to study this! I am very thirsty for knowledge and I learn fast, I just need the right source or sources.

Author: Yappu, 2019-08-14

2 answers

The "False Knight" boss in Hollow Night does not use advanced AI such as machine learning or deep learning, which are learning AI. You can decorate bosses ' patterns over time in Hollow Night, such as when he will attack in this way or jump or hit the nail on both sides of the ground, and your brain memorizes these patterns over time. So False Knight uses a simple AI called: finite state machine. It's a good start to start studying.

What this does that mean? That it has its predefined attacks for example:

  1. jump attack and hit nail in the character's direction.
  2. simple nail attack.
  3. nail attack with chao power.
  4. nail attack in the center of both sides.

Basically the finite state machine will tell the conditions under which it will perform each attack. Example of conditions:

  1. Player is close.
  2. plays is far away.
  3. Player is no air.

A representation in C# could be:

public enum BossStateIA
{
     ExecutandoAcao,
     RequerAcao
}

public enum BossAcao
{
     Nenhuma,
     AtaqueSimples,
     AtaquePulo,
     AtaqueEspecial
}

public class Boss
{
     private BossStateIA State;
     private Acao AcaoAtual;

     private Acao IA()
     {
         Acao acao;

         //Define a próxima ação a ser feita em uma máquina de estados
         //finitas, simplesmente use ifs, and e or. Se o personagem 
         //está perto, longe, pouca vida ets.

         return acao;
     }

     public void Update()
     {
         if (State == BossStateIA.RequerAcao)
         {
             AcaoAtual = IA();
             State = BossStateIA.ExecutandoAcao;
         }

         //Executa o código de acordo com a ação atual.
         //No final da ação defina a variável State para RequerAcao.
     }
}
 6
Author: Weiner Lemes, 2019-08-14 20:09:36

Artificial intelligence for games is a series of patterns performing for certain actions, it is not worth using machine-learning or deep-learning, I would do something like this

bool acao = false;

void Update(){
  if(!acao && Vector3.Distance(transform.position, player.position) < 5){
    Atacar();
    acao = true;
  }else if(!acao && Vector3.Distance(transform.position, player.position) > 50){
    AvançarNoPlayer();
    acao = true;
  }
}

void Atacar(){
 // Atacar
 acao = false; 
}

void AvançarNoPlayer(){
 // AvançarNoPlayer
 acao = false; 
}

And so goes

 0
Author: Andeton Feitosa, 2019-08-14 20:36:11