Search Unity

AI Behaviour Tree Logic Question

Discussion in 'Game Design' started by dinuka_jay, May 20, 2021.

  1. dinuka_jay

    dinuka_jay

    Joined:
    Oct 27, 2018
    Posts:
    9
    Hey all. I believe there's a logical error in my behaviour tree and I was wondering if you experienced AI devs can help me find the issue here. Sorry if it's a bit too small, I couldn't capture everything in one pic with high res.

    This tree is for an enemy AI. I'm setting up behavior for patrol, investigating a last seen position, chasing the player when seen and combat when in range.

    Shared bools used here:
    • Alerted - Set as true when the AI notices a disturbance (seen target but not yet detected). Used as a flag to start the search sequence
    • Detected - Set as true when the AI identifies the target
    • Can see player - Set as true when the target is within the view cone
    • Can't see player - Same variable as above, just set as false
    • Saw something - Set as true when the AI notices something in the view cone, but not confirmed as target. Used as a flag to start the 'wait for detection' sequence where a detection bar fills up for 3 seconds.
    What works:
    • E works. Patrol is triggered first, which is correct since player isn't noticed yet
    • D works. Once alerted, the AI moves and searches the suspected location
    What breaks:
    While C is triggered properly and successfully moves to C1, the C2 is not triggered. The reason I divided them is to determine if the player is still in the view cone after the 'wait' time. Am I doing something logically wrong or potentially overcomplicating this?

    If you've got a better/optimized way of doing these, that would be helpful too. Cheers folks. Thank you!



    Link to zoom in: https://i.ibb.co/CQWb5dm/1-ai.png
     
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    A tool like playmaker really helps with enemy states.

    It really helps break it all down and you can see what is happening at any given moment.

    Alternatively, I’ve seen a lot of people use the built in animation tree to do AI logic.

    In the very least you should be making a proper state system over bools.
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,634
    I'm not a behavior tree expert, but it looks like if C1 is successful then that means "Can see player" is true, so that means "Can't see player" must be false, so "Alerted" will not happen in that case. On the other hand, if C1 is not successful then the parent sequence is broken, so "Alerted" will not happen then either.

    Maybe you meant to have a selector as a parent to these two sequences?