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

Ai programming

Discussion in 'Scripting' started by yanuaris, Mar 15, 2016.

  1. yanuaris

    yanuaris

    Joined:
    Oct 16, 2015
    Posts:
    61
    I'm still into implementing my characters, but i suppose i can ask ahead about AI since the enemy and the player uses the same movesets and is interchangeable in character selection...

    I'm thinking of implementing FSM but i want the enemy to understand the arena and its limited space, reeling players to it, hit and run and so on...
    I have distance, attack range, current energy and HP as its consideration...
     
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    You can do this using NavMesh and NavMesh Agent. Basically, it allows the enemy to have knowledge over the environment and allows it to navigate the level and avoid obstacles and such.

    If you are a beginner with AI, FSM is a good approach since it's simple to design and to understand. And as a programmer, FSM is an essential tool to have at your tool belt, so it's really important to master it.

    As you will gain experience with FSM and as your AI will grow in complexity, you will find it hard or tedious to make changes to your FSM, since any change involves careful modification to the transitions. Also, if you find a part of your FSM interesting and want to reuse it for another AI, you'll find it difficult to extract that part, and rather you would start a new FSM from scratch.

    There are more advanced technique than FSM. For instance, there is the HFSM for Hierarchical Final State Machine. Which has the same basic concepts as FSM, but this time your can build up hierarchies. So, it allows you to put some abstraction in your system, but it has the same inherent difficulties as with regular FSM.

    If you want to build complex and maintainable AI, or just want to prototype out some ideas, Behaviour Tree is the way to go. It requires more knowledge that FSM so it's more difficult to learn and to master, but the effort really worth it. On the long run, it makes writing AI a breeze compared to FSM.

    In my opinion, once you have started working with BT, you won't ever touch a FSM again. I was so enthusiastic while learning and seeing the potential of BT, that I made a scripting tool based on this technique.

    It's available here:

    http://www.pandabehaviour.com

    And this is the dedicated Unity thread:

    http://forum.unity3d.com/threads/released-panda-bt-behaviour-tree-scripting.388429
     
    Last edited: Mar 22, 2016
    Nigey and Kiwasi like this.
  3. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Probably a typo and a detail, but what do you mean here?
     
  4. yanuaris

    yanuaris

    Joined:
    Oct 16, 2015
    Posts:
    61
    Thanks for the offer, i'll try to have a look at BT....

    I tried navmesh and while Offmesh links allows the unit know where to climb or jump, both players and enemy has unique gameplay...like, ascending slopes. like assasin's creed...so the AI needs to know if it can use the thing to ascend the wall...find unique positions or transforms in the map and move to it...flee to a strategic spots and so on...
     
  5. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Indeed Offmesh link is appropriate for dropping and jumping. I'm afraid Unity does not have vertically oriented navmesh for climbing or gliding. It seems you would need to come up with your own solution to implement theses. But I guess that possible by placing some special objects in the scene that purposes (like ladders or ramps).