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. Dismiss Notice

Should I use ML agents or scripted AI?

Discussion in 'ML-Agents' started by Vefery, Nov 14, 2020.

  1. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Basically the purpose of AI in my game is to scare player(s). It's sort of horror where 2-4 players freely wander around the relatively small map and do things, while one AI tries to scare them or make some troubles for them. Right now the AI is just a bunch of actions that are randomly executed depending on some factors (like aggression of the AI or if detected player is alone)
    But at this stage of development the AI feels predictable and just "random".
    Today I found out about ml agents and thought they can spice up my AI, but I have a problem: the AI has an abstract goal. AFAIK neural AIs need to have some kind of reward and punishment to be trained, which is impossibly to code in my case. Right now the only ways to train I can imagine are:
    1) Manually wander around the map in-game and press "scared" button when AI generates scary situation
    2) Manually perform scary actions in-game and somehow feed them to the AI
    So, are any of those (and other) ways to train AI possible? And if they are, does it worth and effort considering I only have basic knowledge of neural networks
     
  2. oopere

    oopere

    Joined:
    Oct 15, 2017
    Posts:
    13
    Not sure if ML-Agents will fit in your Idea. I think is mandatory that you can train with rewards and penalties. Maybe you can simulate the situation, and try to reward the agent.... but you for sure that you are going to need a lot of hours defining this rewards and more training the agents.
     
    Vefery likes this.
  3. dylanfries

    dylanfries

    Joined:
    Jul 11, 2012
    Posts:
    16
    Its probably going to be hard to train the ML agent to do what you want. You can do AI without ML as well, just think about what sort of scenarios you actually want the AI to create? The idea that it should scare the player if they are alone is a good start. Start thinking in terms of what conditions are you looking for, then which action is used when those conditions are met. You can mix in some randomness as well without it being totally random. For example, if a player is alone, you could randomly choose to a) scare them now or b) do some other action to scare them later (set a trap?).

    It sounds like you are sort of on your way there already. AI is just harder to build then it looks. Try to break it down into small steps. Imagine you are the AI? What is your thought process? What conditions are you trying to create? When do you take specific actions and why? You really need to codify that thought process.

    Good luck!
     
    TheShrijanDev and Vefery like this.
  4. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    Usually training an agent requires a clear goal with reward/punishment as indicator for the agent to learn. While it's hard to train an agent with an abstract goal, you can think about what you'll define as a good action in this scenario and try to define a reward based on that.

    On the other hand, another thing you can try with ML-Agents is using imitation learning. You record a bunch of good examples from an expert (either from human play or any other approach) and train an agent to imitate the behavior by showing the agents with the recorded demonstrations. If your demonstrations was able to show correlation between the observation and the expected action (for example, if there's only one person -> do scary things), the model might be able to capture that and learn.
     
    Vefery likes this.
  5. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    That sounds interesting, is there any tutorial/documentation/examples of this method?
     
  6. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Oh right, I should've googled it first, there are plenty of tutorials available