i was hoping u were going to tell me ?, remember this ?:
class sequence: public node
{
// i leave this as an exercise for u to do :)
}
and this ?
void set_up_sequence()
{
selector* sel = my_bt->root->get_child();
sequence* dodger = new node(action::dodge);
sel->add_child(dodger);
sequence* blocker = new node(action::blocker)
sel->add_child(blocker);
...
}
that logic:
shins94 said:
How does game logic find that the AI agent needs to dodge?
it's in the sequence class that u can code this intelligence;
now if u see:
- i created 2 sequence objects and then added them as children to the selector;
if u do it this way, it means that your dodger sequence (and the blocker sequence) will each more likely contain more intelligence than the simple fact of just dodging (and blocking respectively); that means the character needs more intelligence to distinguish when to dodge or when to block; - u could do another way by creating 1 sequence object and adding those 2 actions/tasks (blocking and dodging) to this sequence object; if u do it this way, it means that this 1 sequence object is enough for this character's intelligence to tell the difference between blocking and dodging; (I will show u pseudo for this here below)
shins94 said:
Which information of blackboard is used to find that the agent now needs to dodge by the game logic?
you could create an enum variable such as “enemyNeedToDodgeOrBlock” on the blackb; then in the enemy's sequence class, u create a function testIfDodgeOrBlockNeeded( ) that can update this variable based on this enemy's abilities and current situation (player is attacking or not: this player's action could also go to its own bboard), so in pseudo, it may be coded like this:
// pseudo
// so add to enemy's BB
enum action enemyNeedToDodgeOrBlock
// then in sequence
class sequen...
{
public:
float enemySkillLevel = 0 to 10 (for example from stupid to genius)
void testIfDodgeOrBlockNeeded()
{
auto player = getPlayer()
action pa = player->getBB()->myCurrentAction;
if (pa == action::attacking)
{
if (enemySkillLevel <= 4)
getBB()->enemyNeedToDodgeOrBlock= action::block
else
getBB()->enemyNeedToDodgeOrBlock= action::dodge
}
else
{
...
}
}
}
Now remember last time i warned u that many things were simplified, it is the same here, i have simplified this so that u can understand;
(in practice, the player can advertise his/her action (as an event) and one of the enemy's AI perception properties can capture this advertised event and act accordingly. In this abovementionned pseudo, i'm pretending that the enemy can get player's info through getPlayer( ) for simplicity);
then the next thing to do, in the same sequence class, is to run through each child and check which child needs to respond to enemyNeedToDodgeOrBlock update, again pseudo wise:
class sequen...
{
// remember: "u could do another way by creating 1 sequence object and adding those 2 actions"
// so make sure u have added those 2 actions to be children of this class
// i leave it as an exercise for u to complete :)
bool runActionsOrTasks()
{
...
// get enemys bb
bb* b = getBB()
for (child in getChildren())
if (child->action == b->enemyNeedToDodgeOrBlock)
return child->playAnimation(b->enemyNeedToDodgeOrBlock)
...
return false;
}
}
again, for clarity i have simplified it, but the idea is that the sequence class checks each of its children to see which one matches the BB's variable condition, so if this sequence had 2 children (1 child to block and the 2nd one to dodge) and if bb→enemyNeedToDodgeOrBlock is set to dodge then 2nd child takes action;
notice that the sequence is in the character's AI controller, so this sequence knows what character it belongs to and so the character will animate accordingly;
ok that's it now… u have enough to get going ?
i hope this helps;
all the best… have fun ?