Search Unity

How to implement a Goap AI?

Discussion in 'Scripting' started by hsjaaa, Jun 14, 2019.

  1. hsjaaa

    hsjaaa

    Joined:
    Apr 30, 2016
    Posts:
    29
    Get very interested in Goap AI after watching the video on youtube, want to try to implement something like that in unity.
    The speaker says the world state is a collection of variables, that sounds like could be a monobehaviour with some member variable, attach to a entity to represent entity's current world state. The action still have precondition and effect, which could still be some variable assigned by different goals.
    Planner using Astar would require these action connect each other by effect and precondition, also these action still need some kind of reference to the world state's member variable. So the thing not very understand is that how to make these connections between variable in different classes.
    If have a beAttacking variable in a AttackAction class indicate effect to world state after done this action, it has nothing to do with the variable in WorldState class's beAttacking variable which indicate current attacking target. But this connection is needed to generate the graph for planner, which use A* algorithm to find a possible path through all valid actions to achieve the goal. Also the variable still need to be defined as precondtion or effect to make the connection.
    Use reflection could find property with same name and use custom attributes to define precondtion or effect, but the reflection performance is not good so not a option. There are some C# goap library out there but mostly not maintained or feel heavy and hard to understand.
    Could someone throw some lights on how to implement this kind of system? Very appreciated.