General AI Behavior


TOKENS
Behind the game, we have a Director that keeps track of how well the player is doing and which enemy has token to attack, stay idle or pick up an item around the room. As you will observe during gameplay that if the player is near by the vicinity of enemy, he will be send attack token to dodge himself and injure the player. There is a pattern of beat them up kind of hovering around by the NPC's to make it life-like and they also face towards the player when he is inside the zone.

Director::Director(LevelManager & m_lvlManage, XMFLOAT4X4 _player)
{

    // Cooldown to switch tokens to other NPC's   
    PassoutGrabTokenTime = PASSOUTTIME;
    m_lvlManager = m_lvlManage;
    m_PlayerPosition = _player;

    // Randomizing tokens between different NPC's   
   int thisone = rand() % m_lvlManager.GetNPCs().size();
   m_lvlManager.GetNPCs()[thisone]->SetAction(Actions::ATTACKING1);
   m_lvlManager.GetNPCs()[thisone]->SetPlayerPosition(_player);

   while (true && m_lvlManager.GetNPCs().size() > 1)
   {
        int random = rand() % m_lvlManager.GetNPCs().size();
        if (m_lvlManager.GetNPCs()[random]->GetAction() == ATTACKING1)
          continue;
        else
        {
             m_lvlManage.GetNPCs()[random]->SetAction(Actions::GRAB_WEAPON);
             m_lvlManage.GetNPCs()[random]->SetPlayerPosition(_player);
             break;
         }
   }
  //Once the token for action and grab weapon is assigned the rest of the NPC's are send token for being idle
    for (size_t i = 0; i < m_lvlManager.GetNPCs().size(); i++)
    {
         if (m_lvlManager.GetNPCs()[i]->GetAction() != Actions::ATTACKING1 && m_lvlManager.GetNPCs()[i]->GetAction() != Actions::GRAB_WEAPON)
         {       
                m_lvlManager.GetNPCs()[i]->SetAction(IDLE);
                m_lvlManager.GetNPCs()[i]->SetPlayerPosition(_player);
          }
     }

}

AI Behavior - Attack, Picking Up Item, Stay Idle, Die
Setting up different game state mechanisms involved mapping the goal to be achieved, and transit smoothly between animations. As the gameplay starts, based on the token each enemies perform their tasks, once its done or the cooldown time updates, the tokens are switched. It is also designed in a way where if the player passes near by the enemy the attack token is passed on to a particular NPC giving them chance to attack as well defend. On the other end, pick up item works in a way where if the player gets hurt by the item, then the next one is given the token to do the same. Similarly, once the attack and pick up token has been assigned, the rest of them idle around the player.

When the token set to attack, navigate to the target,
perform the action

if (m_action == Actions::ATTACKING1 && Distance(XMFLOAT3(temp1._41, temp1._42, temp1._43), m_nav->m_current->center) >= 4.0f)
{
    m_velocity.x = Apos.x - temp1._41;
    m_velocity.y = Apos.y - temp1._42;
    m_velocity.z = Apos.z - temp1._43;
}

When the token set to grab the weapon, navigate to the item, hold it, wait for sometime, throw it at the player, or else perform the idle animation.

Comments

Popular posts from this blog

Using DirectXTK Input for Keyboard, Mouse & Gamepad

Pathfinding & Navigation

Milestone I - Basic Setup of Office Retribution