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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[C#] How Can I "Dumb Down" My AI?

Discussion in 'Scripting' started by SwaggyMcChicken, Sep 22, 2015.

  1. SwaggyMcChicken

    SwaggyMcChicken

    Joined:
    Apr 13, 2015
    Posts:
    108
    I'm currently working on a 3D fighter, the movement is kinda unique so it can't really be done with NavMesh, but that's besides the question. I have (I think) the fundamentals down to developing my AI, like running towards the player when too far, running away when too close, blocking when they swing, attacking when they aren't blocking, but I'm curious as to how to "dumb down" my AI, as it's pretty much unbeatable. I've pretty much determined that the only things I can really do is to make it sometimes slip up, like attack when someone's blocking (which stuns the attacker) or forgetting to block, or maybe just delay it using the WaitForSeconds() funtcion (Which I'm having trouble understanding, if anyone could explain like I'm 5 that'd be great) and delay the decisions, or maybe both, depending on the difficulty level. If someone could help, that'd be great. Thanks!
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    you could use a 'dice roll' to decide if the AI does the correct thing.

    ie, you attack, it rolls dice (random 1-6), if value > 4, ai blocks, etc
     
    Kiwasi and Korno like this.
  3. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    You could trying adding personality to your AI.

    For example, an AI that gets angry when receiving a lot of hits so keeps attacking even though the optimum strategy would be to block. This would leave the AI open to hits from the player. Or, how about a defensive AI which defends receiving a lot of hits in a row then attacks if the player pauses. The player could confuse the AI which again would make the AI open to some attacks.

    Or an AI the prefers kicking to punching, leaving it open to different kind of attacks.

    Just a very rough brain dump.
     
  4. SwaggyMcChicken

    SwaggyMcChicken

    Joined:
    Apr 13, 2015
    Posts:
    108
    Yes, I've thought of this also, but it doesn't solve the issue of that instant reaction time x-x
     
  5. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    If you are using coroutines for your AI you could change how long the coroutine yields for to simulate AI reaction time.
     
  6. Smingleigh

    Smingleigh

    Joined:
    Nov 24, 2012
    Posts:
    9
    I don't know how useful it might be (very different genre), but here's how I'm currently tackling a situation where I don't want Godlike perfection from my AI agents.

    Each of my AI agents builds a "snapshot" of the world containing information relevant to fairly high-level decision making, such as aggressiveness and immediate goals. I then make the agents refresh their "snapshot" semi-regularly*. This way, although they're always reacting perfectly to the information they have available, the information they have available can be out of date, and it takes them time to react to changing situations. Smarter agents have shorter refresh intervals and react quickly to changing circumstances, while dumber ones keep attacking when they should switch to defence, etc.

    *by semi-regularly, I mean a time period described as refreshRate - offset + Random.Range(0f, offset) + Random.Range(0f, offset). Varying the refreshRate and offset give interesting variations.
     
    Last edited: Sep 22, 2015
    Rokkimies likes this.