Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

What A.I technique is most suited to my game, FSM, BT, GOAP

Discussion in 'Getting Started' started by arain55, Mar 4, 2020.

  1. arain55

    arain55

    Joined:
    Mar 22, 2014
    Posts:
    2
    I'm creating an RPG, where the NPC's will be able to go about their daily routines (eat, (cut wood if woodcutter) or (make weapon if blacksmith), sleep) but they will also be able to attack you if you attack them. The enemy NPC's such as monsters and other hostile humans will also have daily routine but will attack you on sight. Now I've been reading up on different ways i can go about creating the A.I, such as

    FSM
    BT
    utility A.I
    GOAP

    Right now I'm using FSM, the NPC's can be idle and chase the player then strafe around the player if in range then attack when in range. But I've been thinking ahead and realised that it will be so exhausting creating more states and transitioning between them so i want to use another approach.
    But i don't know which one is the most suitable, i see elements in all which can be useful. Can anyone who's possibly used any of the above (or any other approach i haven't mentioned) inform me of how it helped them or just tell me in general the advantages and drawbacks.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    I'm a big fan of utility AI, because it is very easy to extend and add to without breaking things. It's not so useful when you want to play out a specific interaction, like a scripted mission or whatever. But it's great for a more sandboxy game where you just want all your agents to do what agents in those situations would naturally do.

    Right off the bat you have a bit of a wrinkle here, in that you have a day/night cycle and you want your agents' activities to sync to that. But this is pretty easily handled by not having the "sleepiness" variable start increasing until dusk, and then set the rate at which it decreases during sleep so that they takes about 8 hours before they wake up. That will get them a nice basic daily routine. The others are easy: the "need to work" variable can increase at a steady rate all the time (when not working), but won't be urgent until the next day, so they'll start working in the morning as soon as they've taken care of any more urgent needs (bathroom, eat, etc.). Time your hunger right and they'll stop for some food in the middle of the day, then get back to work.

    The great thing about this is if you interrupt their usual routine — say, they get attacked or even just witness something scary in the middle of work, or even in the middle of sleep — they will switch to more urgent behaviors (fight or flight) until the threat is resolved, and then calm down and get back to work. You can of course do that with state machines or other techniques too — but it requires manually programming in all those transitions. With Utility, it just sort of happens.

    The fiddly bit with utility comes in adjusting all those rates at which the needs increase and decrease. But in most cases, those can be adjusted individually, and it's pretty straightforward. If you have N different needs, you need to fiddle with N things, instead of the N^2 state transitions you might need to consider in other approaches. That's a big win to me.

    And somehow the resulting behavior just "feels" more natural and believable to me, like an organism going about its business, rather than a robot following a script. But maybe that's just me.
     
  3. arain55

    arain55

    Joined:
    Mar 22, 2014
    Posts:
    2
    Thanks alot for the detailed response! You make a very compelling case for using utility A.I, but you mentioned it's not great for specific interactions such as scripted missions, sorry if this is a nuisance of a question but I'm not exactly intelligent and would like to understand as much as i i can, but why is it not suitable for those scenarios and im assuming you let some other system or technique take over the behaviour of the A.I in these scenarios.

    Thanks again for your response and do you have any good reads on utility A.I (books, articles, videos ot whatever).
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    It's not great for those because the whole point of a Utility AI is that you don't directly control your characters — they have needs, and they make their own decisions about how to satisfy them and in what order.

    So if you're trying to do some scripted scenario where the monsters gather behind the barn, and then all charge out, except one of them takes a look at you and bolts because <plot reasons>, it's going to be hard to make that happen with Utility AI. So yeah, in that case you would need to use something else I guess.

    Or, just don't do that. Decide whether you're making a story-driven game or an emergent-behaviors game, and lean into it. :)
     
unityunity