Bots can't seem to flee

Hi,

I am trying to get my bots to flee, rather than engage in combat, but I am struggling to get this to work properly. I'm using the Deathmatch AI team behaviour tree. The first thing I have done is increase the flee probability to 90%, that seems to not be doing anything. Also, I noticed that the flee tasks require the possible target GameObject to not be null, but the reset task within the Damaged sub-tree kept resetting it, so the bot is unable to flee. Disconnecting the Reset task still doesn't do anything, the bots are still not fleeing. I have also increased the minimum health to 100 and lowered the minimum distance to 5, but this doesn't seem to be doing anything. Here is the sub-tree:

Tree.JPG

I'm not understanding why the Reset task was placed after the Has Taken Damage condition, because the possible target GameObject is getting assigned there, and then the value is reset afterwards, so it becomes null for the Should Flee condition. But even if I get rid of it like I did above, the bots still don't want to flee. Is there something I missing here, or maybe I'm not fully understanding the behaviour tree? Any suggestions would be greatly appreciated :)
 
Does the flee task run? What task runs instead of the flee task?

I'm not understanding why the Reset task was placed after the Has Taken Damage condition, because the possible target GameObject is getting assigned there, and then the value is reset afterwards, so it becomes null for the Should Flee condition
That reset task doesn't reset the target, just the cover point, search, and can attack variables.
 
Does the flee task run? What task runs instead of the flee task?


That reset task doesn't reset the target, just the cover point, search, and can attack variables.
So the flee task doesn't run. Either the bot continues to attack and shoot, or the Should Flee task returns false. I noticed that the Should Flee task returns false because of this condition:

C#:
if (m_Attacker.Value == null) {
    return TaskStatus.Failure;
}

If I remove this condition, then it will return true, and the Flee task will throw a NullReferenceException because the m_Attacker value is null. I'm unsure as to why it would be null, after all the bot is in combat and is clearly being hit.

Here is what the Reset task looks like:

ResetTask.JPG
I reimported the Deathmatch AI kit to make sure I didn't make any changes. I had a look at the code and I think I understand, basically if you don't assign any shared variable, then the script won't change it. So the value of the targets shouldn't be changing since nothing has been assigned to them. But I'm still unsure as to why the m_Attacker variable is null if the Possible Target value isn't being reset. Or maybe I'm still not understanding something :unsure:
 
Attacker isn't being reset by that task. Maybe it is being reset somewhere else? The attacker cannot be null as the flee task uses that to determine what to flee from.
 
Attacker isn't being reset by that task. Maybe it is being reset somewhere else? The attacker cannot be null as the flee task uses that to determine what to flee from.
I observed one of the bots in combat, the Has Taken Damage condition will return success, but it will stop at the Should Flee task which always returns a failure. The only other reset task before it is inside the Near Grenade sub-tree, but the condition before it is never satisfied so the Reset task never actually runs. I am using the Team tree, with no changes, so this should be reproducible using the demo scene. Could there be a problem with the behaviour tree itself?
 
I just tried it in the demo scene and the flee task successfully ran. Did you try it in a fresh project?
 
I just tried it in the demo scene and the flee task successfully ran. Did you try it in a fresh project?
I think I understand the issue here. In a fresh project it worked fine, but within my project, since I also have the PUN add-on, it won't work because of a bug with the damage originator. The Has Taken Damage uses the OnDamage event and as I recall, the attacker GameObject parameter was always returning null, hence why the Possible Target is null.

C#:
private void OnDamage(float amount, Vector3 position, Vector3 force, GameObject attacker, Collider hitCollider)
{
    m_DamageFrame = Time.frameCount;
    m_Originator = attacker;
}

The m_Originator (which is null) is then assigned to m_Attacker:

C#:
public override TaskStatus OnUpdate()
{
    if (m_DamageFrame >= Time.frameCount - 1) {
        if (m_Attacker.IsShared) {
            m_Attacker.Value = m_Originator;
        }
        return TaskStatus.Success;
    }
    return TaskStatus.Failure;
}

Then the Should Flee task will return false since m_Attacker is null. I asked a question about this problem here:

I should have mentioned the PUN add-on, I was testing in offline mode and sort of forgot about it ? I'll wait for the January update for the PUN add-on and I will try again, hopefully the Flee task will work. Thanks for your assistance Justin (y)
 
Last edited:
Top