KungFu Style Movement and Instant Reaction

This blog is going to be about how we planned on to design Kung-Fu style movement of the AI and how we planned out the instant reaction of the player in terms of making the combat more challenging and interesting on the same end.

How we went on achieving IP-man style fighting style -
So when the director sends in the token for attack, that particular enemy navigates its path to the target, i.e., the player, once it reaches certain distance, we command the AI to perform the attack
animation and defend from the hits of the player by making it rotate around and face inverse of the player taking 2 steps forward. Once its done with it's turn the token immediately gets passed on to other one, the process repeats on.

Take a look at it -

// Token to attack and if the enemy who has got the token to attack isn't on the same nav node as the
   player
if(m_action == Actions:: ATTACK && m_currPly != m_nav->m_current)
{
       //Go to the player
         GoHere(m_nav->m_current->m_leftTri->m_center, m_nav);
}

// Face the player by taking myPos and  PlyPos by using Look Algorithm
XMFLOAT4 myPos;
myPos.x = getTransform().Translate._41;
myPos.z = getTransform().Translate._43;
XMFLOAT4 PlyPos;
PlyPos.x = m_playerPosition._41;
PlyPos.z = m_playerPosition._43;
XMVECTOR upVec = XMVectorZero();
upVec.m128_f32[1] = 1.0f;
upVec.m128_f32[3] = 1.0f;
XMFLOAT4x4 RotateTemp;
XMStoreFloat4x4(&RotateTemp, XMMatrixInverse(nullptr, XMMatrixLookAtLH(XMLoadFloat4(&myPos), XMLoadFloat4(&Ppos), upVec)));

Similarly we can perform Look At algorithm for the player to face the where the NPC's move around.

How do you look for the target near by -
The situation where the player can see more than one enemy in it's view frustum, we want the player to only go attack to the one nearest.

// If there are enemies on the field, if they fall under view frustum
for(int i = 0; i < badGuys.size(); i++)
{
       vector<XMFLOAT3>NPCPos;
       if(FrustumToCapsule(m_viewFrusttum, badGuys[i]->GetBodyCapsule()))
          {
                  //Get the curr position
                   XMFLOAT4x4 temp = badGuys[i]->getTransform().Translate;
                   XMFLOAT3 EmyPos = XMFLOAT3(temp._41, temp._42, temp._43);
                   NPCPos.push_back(EmyPos);
           }
}

// Compare the playerPos with that of the near by the Enemy and pass the tag
if(NPCPos.size() != 0)
{
   XMFLOAT4X4 temp = getTransform().Translate;
   XMFLOAT3 myPOS = XMFLOAT3(temp._41, temp._42, temp._43);
   XMFLOAT3 closestPOS = NPCpos[0];
   float _distance = Distance(myPOS, closestPOS);
}

Comments

Popular posts from this blog

Using DirectXTK Input for Keyboard, Mouse & Gamepad

Pathfinding & Navigation

Milestone I - Basic Setup of Office Retribution