Search Unity

Help with GOAP Game design

Discussion in 'Game Design' started by Censureret, Feb 4, 2021.

  1. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    I am quite new to the Goal Oriented Action Planning (GOAP) concept and was hoping some of you could help me with the design process of my project :)

    Let me set the scene:

    I am building an RTS siege simulation and want my enemy AI to defend a castle:

    upload_2021-2-4_11-1-49.png

    The goal for the player is to breach the castle gates and take the middle capture point to win the match

    I want my enemy AI to take action to protect these points and/or destroy the enemy ram.

    My idea is to have three different types of AI agents:

    - Swordman (uses sword and shield)
    - Archers (uses bow and arrows and can shoot from afar)
    - Brutes (uses heavy weapons but work alone)


    The idea is that archers of course want to stay on the walls shooting down on the enemy while the swordsmen want to get up close either defending a point or destroy a ram.

    So what types of actions and goals could I design to make this look realistic? :)
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    If it is just simple mechanics, I would just make something like:
    • If archer, go to wall point A or B.
    • If swordman, or brutes, go outside of wall.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    that sounds like a state machine, not a goal oriented action plan.


    first of all, you also need swordmen on the walls if the enemy has a siege tower.
    and why a sword of all weapons? what about spears, axes and polearms?

    anyway, what you wanna do is break it down to an end goal and actions your actors can take.
    the defender ai goal is to protect the castle and subjects and rid the castle of all hostile entities,
    you need to provide your GOAP algorithm with a technical representation of said goal (IE attack all entities marked as hostile and avoid incoming damage to castle walls and subjects)
    and you also need to provide him with actions it can take to accomplish said goal,
    for example "defending the walls", this action will make the entity go to the walls, you need to rank how good the action is for the entity to take, if the walls are under fire and they offer no protection(crenellations) it will decrease the action score, if you're a ranged unit and there are enemies you can hit from the walls it will give a high score, if there is enemies climbing the walls(ladders/siege tower/etc) and you're ranged you'll have a lower score if you're melee you're gonna have a higher score.

    you understand where i'm getting at?

    you might wanna read a book called "AI for games" by ian millington and john funge


    there are some great channels on youtube that explore medieval combat(and life in general) if you wanna know specific tactics to implement, i'm working on a medieval style game too and i find them a great information source.
    like Shadiversity (european castles), Metatron(roman/greek/asian stuff), Skallagrim(viking stuff), Lindybeige(random babbling but he make some great points, haha)


    if you expand more about how the game and the mechanics we might able to offer better insight and interesting tactics that have some relation to the game, with out that it's just talking about real life medieval tactics in general.
     
    angrypenguin, JoNax97 and Antypodish like this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Sure. I assumed simplest solution.
    I didn't want to assume that however, unless OP does specify that this indeed is required.
     
    SparrowGS likes this.
  5. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536

    Yeah but the title is "Help with GOAP Game design", haha

    ofcourse, that's why I also said

     
    Antypodish likes this.
  6. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Thank you so much for your response I would love to break down the mechanics of the game :)

    So first of all it could be any weapon I just chose a sword for simplicity.

    The goal of the game is for the player to conquer the castle for this purpose he has a battering ram this ram will get closer and closer to the gate of the castle and once it reaches the gates it will (after a certain time) destroy the gate allowing allied units to run through.


    Should the ram be destroyed (which is a goal for the enemy ai) the player can tell his units to climb the walls and open the gate from the inside. (of course, the enemy units wants to stop him from doing this)

    One last thing. During the battle the player will be able to go down directly on the battle field and fight along side his army this means that some actors might want to kill the player (since he is a high value target)

    Does this make sense? :D
     
  7. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    There is ofcurse a goal to kill enemy units archers can do this by shooting from afar (from the walls)
     
  8. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    your very welcome, and it does make sense but not was I asked, you gave some description of the game, but still nothing about the battle mechanics, the map or anything, so i'm just gonna start blabbing.

    I'm getting a quick RTS game kind of vibe, start in attack formations with selected blah blah blah and play to the end of the battle, I assume in the order of 20-30 minutes to an hour tops?

    or is the castle conquering part of a greater campaign?
    are you always the attacker?

    is the battering ram central to every attack or is it just one of the attack options?
    can I order my men to climb the walls before the battering ram is destroyed?
    is it set on one "face" of the wall or can you attack a castle from 360 degrees in some scenarios?

    how are the defenses set up, what do walls do besides be a wall and have someone standing on them?
    do they have crenellations? machicolations? what type of battlements are there?

    crenellations (the iconic "teeth" castles have) can provide cover from archer fire and be destructible with artillery like cannons and catapults/trebuchets

    on walls without machicolations(look that up if you don't know the word) you can't attack directly down so attackers can take cover at the base of the walls(if there isn't another wall looking at them from across) and set up all sorts of stuff like ladders, maybe explosives?

    do towers have any special effect?

    what's going on with the gates? in castle gatehouses like that the gate itself is as far back into the inside of the wall as possible and you holes on the ceiling (or on the floor if you're on top of the gatehouse) called murder holes where you can safely attack down anybody attacking the gate, shoot arrows, pour boiling stuff(BTWthey didn't use oil back than - way too expensive, either hot water or hot sand)

    also you usually have inner separation, so if the attackers manage to take down one gate or climb the exterior walls you can fall back one layer, lock another gate and still have a secure position, and if you design your castle right the attackers can't bring siege equipment past the first layer (can still be in range of a trebuchet or something)

    you might wanna take a look at some castles layouts and 3D reconstructions, also note that in-ward facing battlements (crenellations and etc covering from the wall to the inside of the castle) can be a very bad thing,
    as a defender there is hardly a scenario where you have control over the walls and the attackers are on the inside of the castle with no access to the walls, it costs extra to build and provides no help with attackers from the outside
    and if attackers do take the walls and you have to fall back to the city, guess what - they now have said protection from you. (example)
     
  9. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    WOW Thank you so much for all the great inspiration let me try and go into depth with the different options there are:

    The gameplay in general
    -----------------------------------

    So what we are making is a demo project in this demo project you will only be attacking the castle which is a part of the storyline (we are a mix of an RPG / RTS) so it will be the last event of the demo.

    This means you are always the attacker and the AI is always the defender

    There will be multiple layers of walls so that if the first is breached the AI will fall back to the second

    Towers
    -------------------------

    As of right now the towers only serves as a means to get to the walls


    Walls
    -----------------------------

    The player units are able to climb the walls using ladders and the enemy are able to use walls to either defend the castle gate open mechanism (look below) or to fire arrows at the enemy army / Ram

    Also, this is a defending point if the player attempts to climb them



    Castle Gate
    -----------------------------

    The castle gate is inside of the wall there is currently no "murder holes" however on top of the gate (accessible from the walls) you can open the gate from the inside (this is of course something the player can do) he can do this regardless of his ram being destroyed or not however if his ram is destroyed this is the only way to let his army in (outside from climbing the walls)

    Currently, there is no way to throw down (oil or hot water) but we might add that at some point it's a great idea!



    In general, the whole thing is very "simplified" as it is a demo of our gameplay but I still think we can make some great AI that can choose between these goals


    it is worth mentioning that the player AI will be controlled using something like a "command" pattern (if you have a better idea then I'm all ears) and the Enemy AI will be using a GOAP type approach (again if you have ideas I am all ears)

    Did this get you closer as to what I'm aiming for?

    Again your help is greatly appreciated
     
  10. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I'm kind of envisioning the siege battles from total war.

    That means you can put a lot of complicated behaviors that are prone to fail in a dynamic environment(so you need a great variety so you'll always have something to do) "on rails".
    simple stuff like replacing the archers on the walls with melee infantry when you detect it's being boarded should be relatively simple, also the archer should not just stand aside and wait, they should re-arm and reposition on the next layer waiting to provide cover fire when you inevitably lose the walls and the melee guys need to fall back

    well, what are they going to do?
    in real life they provide line of sight, you can translate this into the game if you have something like stealth units that can creep up on the wall, better towers with more men in them can detect this sort of enemy easier.
    one other thing they do is provide more "fire power" per square foot, stacking archers on top one another(in building footprint, not actual flooring)
    they also usually only fire though arrow loops* so the archers in the towers are safe (besides the guys on the top of the tower in some cases, but they also might be too high for the enemies projectiles to reach so they don't actually need any cover)
    *arrow loops, or arrow slits are those vertical narrow slits you fire though in the towers, some castles also have them on the crenellations(or more specifically the merlon, which is the high part of the crenellations) so the archers are better defended all over the walls.

    okay, so i gather that siege towers are not a thing here, where do the ladders come from? in the old total war games you had to build and bring them into battle, like every other siege engine, in the new warhammer total war when you tell units to climb the walls when they're not in a siege tower they just go to the walls and pull a ladder out their asses (I personally really hate that, TW has been slowly deteriorating for a while now)

    I don't know what that means, does that mean the defender can attack back and recapture the gate/strategic point?

    Okay, so if you're just doing a simplified demo, why do you wanna do a GOAP AI, this is some really complex stuff to get right, maybe take @Antypodish s advise and use a "simple" state machine, you can still do really sophisticated behviors with them, can extend them a bit to a hierarchical state machine to get some more complex stuff.

    you can still make an AI that uses a state machine enforce the completion of some goals and tasks, it's all very arbitrary stuff so don't get too caught up in the names.

    GOAP AI made in a small scale basically acts like a FSM and can be way harder to implement, they really shine in large environments with rather generic tasks that have many ways to get done.
    I'm not sure what is this "command" pattern you're speaking of.


    btw, sound like a cool project, where is this going to be?
     
    Last edited: Feb 4, 2021
    Antypodish and EternalAmbiguity like this.
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    Is there a reason why you're pursuing GOAP instead of, say, an HTN planner or hierarchical FSMs or behavior trees? As SparrowsNest writes, GOAP tends to work better for independent agents with generic tasks. But it's probably not an ideal fit for group coordination. In the scenario you describe, you probably want the enemy agents work in concert.
     
    SparrowGS and EternalAmbiguity like this.
  12. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    I am so sorry for the noob question but what is a HTN planner?

    And wouldn't a GOAP system work if it was lifted up to a "Group" controller getting the goals and then providing agents with the inputs such as Go to locations and attack target.

    Then having the agents have their own Goals such as Survive / Attack?
     
  13. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    It's a Hierarchical Task Network planner. Many tactical combat games have switched from GOAP (those few that were using GOAP, as most still use behavior trees/FSMs) to HTN planners over the last 10 years or so. The canonical example is UMCP's SHOP. There are also various implementations in Unity.

    If you use a GOAP group controller and then separate GOAP controllers for each agent, it's difficult for those agents to coordinate their individual actions with each other. You might be able to use a shared blackboard for some coordination. Or, if it's a comedic game, GOAP might be a good choice to watch the agents constantly step on each others' toes.
     
  14. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Okay do you know where i might find a good implementation? (is there a good asset on the unity asset store? or a github project that you know of?)

    Also using Goap what about a structure like this:

    upload_2021-2-8_15-21-52.png
     
    Last edited: Feb 8, 2021
  15. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    I haven't used this HTN planner implementation by Boris Krylov, but it's been updated fairly recently so it should work with modern versions of Unity, and it's MIT license open source, so you can just download it and give it a try.

    In your picture, notice how Group Goals and Single Unit Goals are separate. That's the problem. There are ways you can get them to coordinate, but that picture by itself should suggest that maybe GOAP isn't the best fit for your game design. You can make it hierarchical, but then you might was well use an HTN planner.
     
  16. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Thank you for your answer.

    The github you linked to seems to be a work in progress the documentation is not really there so i wouldn't know where to start :(

    Do you know of any other open-source projects? I can't seem to find a lot that seems to tackle the issue i have (even though i think that my issue should be something that a lot of games has to handle? )
     
  17. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    For an overview of how HTN planners are used in games, see Tommy Thompson's article Behind the AI of Horizon Zero Dawn, Guerilla Games' presentation on HTN planners in the Killzone games, and the GDC Vault video Beyond Killzone. Andrea Tucci also has a good presentation on HTN in Videogames, as well as one on SHOP2. Looks like you can find lots of open source SHOP2 implementations in C# on github. I'm sure there are other HTN planner implementations for C#, too.

    Of course, HTN planners aren't the only way you could go. I just think that they're a better fit than GOAP in this case. But you could use behavior trees, hierarchical FSMs, etc.
     
  18. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Say that you used Behaviour Trees how would you do this? Would each agent have their own as well as the groups or would you only control the group's behavior?
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    They could have tasks that communicate. Play around with Behavior Designer's Tactical Pack WebGL demo to see what it might look like.
     
  20. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    I just read through the whole of:
    http://www.gameaipro.com/GameAIPro/GameAIPro_Chapter12_Exploring_HTN_Planners_through_Example.pdf


    From what I can see the HTN planners still seem to focus only on one agent. and seems very similar to GOAP? Could you elaborate on how I could implement single-agent behavior with a group behavior with HTN? Should each agent have an HTN planner or only the group or what did you have in mind?
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
  22. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Thank you for those details.

    What about the experimental package (AI Planner) from unity? Do you think that would be suitable for my case?
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    I haven't dug into it. It looks like it requires ECS, so that's something to consider. From a very brief glance, it looks like a STRIPS planner. If you're using ECS and decide to go with that kind of planner, it's probably worth investigating. If your game calls for more coordinated activity, a different approach may be better. Not that I have anything against STRIPS planners; that's what Quest Machine uses. But Quest Machine works on the level of individual, independent NPCs generating quests to satisfy their own personal goals.
     
  24. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    The last I checked, it uses burst-compiled jobs but doesn't particularly require ECS, but its main API is not ECS-friendly.
     
  25. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    imo this is something that you cannot think in stasis because it's affected deeply by how the rest of the game is structured, and as a designer, what exactly you want your players to do

    History talk is interesting and all, but games rarely have to adhere to reality, they just have to be immersive enough to suspend a player's disbelief.

    As someone who has experience with GOAP (specifically LGOAP
    ) I can give you 2 major advice about this.

    1. Plan out the behaviour first in concrete terms, because feeding your entire game state at a global level to GOAP is not gonna help, even if you discount the performance considerations.
    2. The main advantage you have with GOAP is one of a higher level of abstraction, and use that to your advantage once you've determined the behaviour.
     
  26. Jacky_Boy

    Jacky_Boy

    Joined:
    Dec 8, 2013
    Posts:
    95
    @kurroarashi How does the planner handle interrupted actions? Can actions be interrupted in the first place if a higher priority action takes precedence?
     
  27. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Scrapped it all. I have a much better version of it in place now.

    In my new system, if there's a change in the blackboard, it'll generate a new plan, and the original task will have an abort callback triggered.