Search Unity

RaptorAI Multi-Purpose AI Engine - States, Behaviour trees, Senses, Navigators, Waypoint Systems +++

Discussion in 'Assets and Asset Store' started by Ruben_Chris, Jul 8, 2018.

  1. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Tested on Unity 5.5, 2017 and 2018

    RaptorAI Multi-Purpose AI (RAMPA), also known as RaptorAI 2, is an artificial intelligence engine that simplifies the process of creating AI for your game. The system is built with flexibility and customizability in mind and can therefore be used for a variety of different purposes. It is centred around AI agents that use states, behaviour trees or a mixture of both along with navigators and senses (sensors) in order to create a complete AI experience. This is what defines a multi-purpose AI engine.
    You can check out the asset store page here: https://assetstore.unity.com/packages/tools/ai/multi-purpose-ai-engine-122284

    Included in the package:

    Finite State Machine that uses states (C# scripts) to control AI behaviour.

    Behaviour Tree System for visual scripting using behaviour trees to control AI behaviour. Easily debug behaviour trees by replaying ticks and using the Debug node.

    2 Navigators: Navmesh Navigator for using unity's built-in navmesh system and Astar Navigator for using Aron Granberg's A* Pathfinding Pro. Switching between navigators require no changes in existing states or behaviour trees. Simply change navigator with the click of a button!

    4 Senses (sensors): Visual Sense for detecting Visual Objects with line-of-sight functionality, Audio Sense for detecting sounds like footsteps and Scent Sense for detecting "smells" if you are making animal AI or something similar. In addition to this, there is a Fast Camera sense that's faster than visual sense for detecting objects (with line-of-sight as well).

    Simple or Advanced Waypoint systems that can be used for anything from simple patrol routes to complex maze systems. Caching is possible for advanced systems to avoid expensive re-calculations.

    Animation Profiles for mecanim that sets various mecanim variable values to support AI animation.

    Auto Slope Module that automatically rotates agent to match terrain slope. Supports both terrain data and raycast mode for calculating normal.

    AI Memory and AI Database for storing values for easy retrieval. These values can be inspected during runtime and traced to find the script that added the value, which results in extensive debugging capabilities.

    Extremely flexible as you can create your own navigators, senses / objects, behaviour tree nodes, modules and presets!

    Platform independent: Not tested on other platforms than Windows, but the engine is built upon Unity's engine and pure C# code, so it should support all platforms unity supports. Contact me if it doesn't.

    Presets that contain functions that let's you do calculations and speed up development.

    AI Tags that can be used as an alternative to the unity tag system.

    Full source code included along with summaries, tooltips and several example scenes. Full documentation is of course also provided.

    Basic Group System that lets you define groups and attitudes towards other groups. Currently only limited support for this.

    Screenshots and videos will be found at the asset store page. Contact me if you have any questions.

    Official website: http://flamingraptor.com
    Old RaptorAI 1 thread can be found here: https://forum.unity.com/threads/rap...ates-advanced-waypoint-systems-senses.451814/
     
    Last edited: Mar 2, 2019
  2. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Is there a evaluation version for this asset?
     
  3. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    No, there is not an evaluation version available. Let me know if you have any questions or doubts that you want me to clarify.
     
  4. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Are there some examples how to build my own behavior nodes and navigators, since I need some flying and swimming NPCs. Can I use coroutines in that stuff?
    Is your Visual Sense camera mode 3d or flat?
     
    Last edited: Sep 17, 2018
    Ruben_Chris likes this.
  5. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky!
    Not long ago I updated the documentation and it now includes how to create your own navigators / behaviour nodes. You can check out the documentation at the website (refer to chapter 4 - extending the engine). The documentation is designed for 2.01, ̶w̶h̶i̶c̶h̶ ̶i̶s̶ ̶a̶n̶ ̶u̶p̶c̶o̶m̶i̶n̶g̶ ̶u̶p̶d̶a̶t̶e̶ ̶(̶w̶a̶i̶t̶i̶n̶g̶ ̶f̶o̶r̶ ̶a̶p̶p̶r̶o̶v̶a̶l̶ ̶b̶y̶ ̶u̶n̶i̶t̶y̶)̶,̶ ̶s̶o̶ ̶n̶o̶t̶ ̶a̶l̶l̶ ̶p̶a̶r̶t̶s̶ ̶o̶f̶ ̶i̶t̶ ̶a̶p̶p̶l̶i̶e̶s̶ ̶t̶o̶ ̶2̶.̶0̶ ̶(̶c̶u̶r̶r̶e̶n̶t̶ ̶v̶e̶r̶s̶i̶o̶n̶)̶. Update: v2.01 has now been released and is available for download.
    Full source code is also provided, so you can also check out the navigators / nodes that comes with the package.
    Coroutines are not supported as the engine uses it's own update system.
    The Visual Sense camera is 3D. It basically creates a collider based on a normal unity collider, so it will detect anything within what you can see in that particular camera. Line-of-sight is of course also included.

    Let me know if you have any further questions.
     
    Last edited: Sep 19, 2018
  6. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Chris,
    bought your asset, where do I have to put a custom navigator script so that it appears in the controllers navigator list?
     
  7. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky.
    Thank you for showing interest in my asset.

    You can put it wherever you want it, as long as you remember to update the navigator cache (Other tab -> Scan for scripts). It scans the entire assets folder, so it doesn't matter where you put it.

    - Ruben
     
    Last edited: Sep 20, 2018
  8. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben,
    can I use Raptor only with A* Pathfinding Pro or with the free version as well?
     
  9. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    The Astar Navigator works with both the free and pro version.
     
  10. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben,

    how can I access the AI Memory from a sense?
     
  11. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky,

    If you are creating your own custom sense, there is currently no variable you can access to get access to the AI Controller. If you need access to the memory from your custom sense, you can use "GetComponentInParent<AIController>().aiMemory".
    I will add an "aiController" variable that can be used within senses / objects in an upcoming update.

    In addition to this, creating custom senses and objects will be included in the upcoming documentation update as well.
     
    Last edited: Sep 22, 2018
  12. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    I'm making AI for a shark where I can't use navmesh. So I've written my own navigator which is moving a RigidBody in the top object. If I add then your VisualSense to my shark and use the camera mode, the pivo goes somewhere in in front and the movement gets confused. So I wrote my own visual sense.
    There should be a way to change the navigators speed.
     
    Last edited: Sep 22, 2018
  13. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky,
    Could you please share some screenshots of the AI Controller (navigators and components tab), structure in the hierarchy and the actual scene view?
    If you could also provide the code you used, that would be helpful.
    I will help you fix your problem to the best of my ability. As far as I know, there shouldn't be a need to create your own visual sense.
     
  14. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Did it already and it works like a charm!

    The problem was that my navigator controls a rigidbody in the root object:
    upload_2018-9-22_14-38-29.png

    When I add you visual sense everything works fine as long I dont use the camera (colliders are no problem), the pivot stays in then center of my shark:
    upload_2018-9-22_14-42-24.png

    But when I switch to camera mode, the pivot moves in front of my shark:
    upload_2018-9-22_14-45-53.png
    Due to the longer leverage the shark is rotated up/down which drives my collision detection crazy.
    But no worry, with my own sens solution it works well.

    Thanks for your support, BTW very nice well designed asset:)
     
    Last edited: Sep 22, 2018
    Ruben_Chris likes this.
  15. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    I see what your problem was now. I'm curious though, did the problem happen when rotating it through a script or through the editor? I tried replicating your problem and I see that it changes the pivot as long as you have the pivot mode set to 'center' (see picture below).

    Rotating the agent using this mode results in a rotation around the 'center of mass' and that is (obviously) not what you want. However, if you change the pivot mode to 'pivot', the pivot is back at the original place again (see picture below).

    After doing that, the rotation works fine in the editor.

    That being said, when I tried rotating the agent using a script, it used 'pivot' mode for rotation even though my editor mode was set to 'center'. So, unless you tried rotating it through the editor, this shouldn't be a problem.
    Anyway, I'm glad you found a solution for it.

    And by the way, I appreciate that you like my asset :)
     
  16. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    I found one issue, when you changing things like states or navigators, the old ones stay often in the AI Settings folder. I had one time the problem that my navigator stopped working and even Unity starts hanging without any changes in my code. The final reason was that I had added [RequireComponent(typeof(Rigidbody))] to my navigator and your asset added then an other RigidBody to the AI Settings folder. Maybe you should take a look on this.
     
  17. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben,

    could you add an int value to the animation profiles for condition and actions, that would it make possible to run animations per index (eg. Substates with multiple idles or attacks)
     
  18. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    I would not recommend using the RequireComponent attribute on your navigator as it adds the rigidbody to the AI Settings gameobject like you said. Right now, there is a built-in function that you can overwrite in senses / objects that replaces Unity's "RequireComponent" attribute. This is not supported for navigators at this point, but I can make it supported in the next update. This would mean that it automatically adds your rigidbody to the top parent instead of the AI Settings object.

    When you switch navigators / states, they are not automatically deleted from the AI Settings gameobject. You can delete all unused navigators / states by clicking the "Clear AI Settings for unused states" button in the Other tab. The reason this doesn't happen automatically is because if you want to switch back again, you do not need to change all the values again. If they are deleted, all values are reset. In an upcoming update, I can add the ability to change whether or not this happens automatically or not and let you decide which option suits you best.

    Yes, I can add a int value to the animation profiles.
     
  19. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben,
    could you add a function to change the navigator speed in the next version and it would be nice if one could use an other action set from the same profile as fallback action.
     
  20. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Do you mean another function for navigators, so that you can call "MyNavigator.ChangeSpeed" or something similar?

    Sure, I'll see what I can do.
     
  21. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Yes, example is when you have an AI wander and it sees an enemy I would like to change the speed to chase the enemy.
    I just played a bit with your behaviour tree, there should be more examples how to use it and more documentation.
     
  22. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Sure, I can add that ability to navigators. I will also try to make some more examples around the behaviour tree system.
     
    StevenPicard likes this.
  23. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Great, thanks:)
     
    Ruben_Chris likes this.
  24. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben,
    when I add a controller.animator.SetTrigger("Attack1") to a behaviour I get following error:

    "UnityEngine.UnassignedReferenceException: The variable _animator of AIController has not been assigned.
    You probably need to assign the _animator variable of the AIController script in the inspector."
     
  25. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky,
    Have you assigned the Animator variable in the Animation tab in the AIController?
     
  26. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    That was the first I would try, but there is nothing to assing the animator:
    Unbenannt-1.png
     
  27. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    I see. That is because it is hidden until you select an AI Animation Profile (currently it is set to "None"). I can change it so that it is always visible in the next update. I can see how it's useful to use the variable even though you do not have an animation profile assigned.
    A quick fix you can do is to assign it an empty animation profile. It's not ideal, but it will fix the problem for now. Alternatively, you can get the Animator component by using the GetComponentInParent function that Unity provides (if your Animator is attached to the top parent)
     
    Last edited: Sep 26, 2018
  28. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    It would be nice to have a combo box with all states (like the one in the start state) available in the states parameters. Then I don't have to hard code what the next state or states should be. I do this atm with a string field which is not very comfortable.
    The handlig of your behaviour tree is very awkward at the moment, it should be possible to replace nodes with others without having to delete them and one should be able to move whole branches to another node or level.

    Any idea when then next version will be released?
     
  29. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    I'm not entirely sure if I understand what you are looking for here. Do you mean the "state type" field in the control node? If you could please eloborate, that would help.

    I will add it to my to-do list.

    Do you mean the ability to move one node and its children to a higher layer? Currently you are able to do this with the index, but not the layer.

    I don't have a specific date, but I will try to release a new version by the end of next week :)
     
  30. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Let's say I have a wander state with a visual sense looking for a target. I added now a string field nextState to the wander state with the name of the state that should be called when the sense detects a target (ChangeAIState(System.Type.GetType(nextState));), this way I can decide later what state should be called (state is not hard coded). To make this more comfortable it would be nice to have a combo box with all available states in the controller, like the one where you select the first state.
    Shortly spoken just a way to add a combo box as a state parameter, which would be anyway usefull. You have one in the behaviours but not in the states.
     
  31. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Ah, I understand what you mean now. I will have a look at implementing this as well.
     
  32. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Thanks, I try to make the states more versatile, here a wander state as example:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.AI;
    3. using System.Collections;
    4. using RaptorAI;
    5.  
    6. namespace FRL
    7. {
    8.     public class Wander : AIState
    9.     {
    10.         public float wanderSpeed = 5.0f;
    11.         public float minDistance = 10.0f;
    12.         public float maxDistance = 20.0f;
    13.         public float minWanderTime = 5.0f;
    14.         public float maxWanderTime = 10.0f;
    15.         public bool checkEnemies = true;
    16.         [Tooltip("Name of used visual sense")]
    17.         public string senseName = "Eyes";
    18.         public AIObject target = null;
    19.         public string varName = "EnemyFound";
    20.         public string nextState;
    21.         //-----------------------------
    22.         private float wanderTimer;
    23.         private float wanderTime;
    24.         private AISense sense = null;
    25.         private NavMeshAgent agent = null;
    26.      
    27.         public override void UpdateState()
    28.         {
    29.             wanderTimer += Time.deltaTime;
    30.  
    31.             if (wanderTimer >= wanderTime)
    32.             {
    33.                 wanderTimer = 0.0f;
    34.                 wanderTime = Random.Range(minWanderTime, maxWanderTime);
    35.                 SetNewWanderDestination();
    36.             }
    37.             else
    38.             if (aiNavigator.ReachedDestination())
    39.                 SetNewWanderDestination();
    40.  
    41.             if (checkEnemies)
    42.             {
    43.                 if (sense)
    44.                 {
    45.                     if (sense.IsAIObjectDetected(target))
    46.                     {
    47.                         aiMemory.SetItem<AIObject>(varName, target);
    48.                         if(nextState != "")
    49.                             ChangeAIState(System.Type.GetType(nextState));
    50.                     }
    51.                 }
    52.             }
    53.         }
    54.         public void SetNewWanderDestination()
    55.         {
    56.             aiNavigator.SetDestination(presets.CreateWanderPoint(new Vector2(minDistance, maxDistance)));
    57.         }
    58.         public override void OnStateSwitch(AIState toState) { Debug.Log("Wander stopped"); }
    59.  
    60.         public override void OnStateStart()
    61.         {
    62.             Debug.Log("Wander startet");
    63.             agent = GetController().GetComponentInParent<NavMeshAgent>();
    64.             agent.speed = wanderSpeed;
    65.             wanderTime = Random.Range(minWanderTime, maxWanderTime);
    66.             wanderTimer = 0.0f;
    67.             if (aiDatabase.DoValuesExist(senseName))
    68.                 sense = GetAISense(senseName);
    69.             SetNewWanderDestination();
    70.         }
    71.  
    72.         public override SerializableVariableCollection GetVariablesToSerialize()
    73.         {
    74.             return new SerializableVariableCollection(new SerializableVariable[] {
    75.                 new SerializableVariable ("wanderSpeed", "Wander Speed"),
    76.                 new SerializableVariable ("minWanderTime", "Min Wander Time"),
    77.                 new SerializableVariable ("maxWanderTime", "Max Wander Time"),
    78.                 new SerializableVariable ("minDistance", "Min wander distance"),
    79.                 new SerializableVariable ("maxDistance", "Max wander distance"),
    80.                 new SerializableVariable ("checkEnemies", "Check for enemy"),
    81.                 new SerializableVariable ("senseName", "Visual sense name"),
    82.                 new SerializableVariable ("varName", "Variable Name"),
    83.                 new SerializableVariable ("target", "Enemy object"),
    84.                 new SerializableVariable ("nextState", "Next State")
    85.             });
    86.         }
    87.     }
    88. }
     
    Ruben_Chris likes this.
  33. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    That seems like a good idea. I like your code, it looks very good :)
    I am planning on adding multi-purpose states (or something similar) that lets you create simple AI quickly without writing extra code. Right now the example scripts don't really work well on their own and is only there to give you an idea of how you might create your own states. It might take a while before this is implemented though and it will not be part of this next update.

    On a side note, I worked on your idea to add dropdown functionality to the variables. I added support for states, behaviours, navigators, senses and objects and you can even create your own custom dropdown menu. You can see the result below.

    Capture.PNG

    Capture.PNG


    You use System.Type.GetType in order to convert the strings to types like shown below.
    Code (CSharp):
    1. ChangeAIState (System.Type.GetType(state));
     
  34. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Great ideas, can't wait for it;)
     
    Ruben_Chris likes this.
  35. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Version 2.1 has now been released and is available for download. You can check out the changelog and updated documentation on the website.
     
    franky_li and StevenPicard like this.
  36. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    Hi Ruben, I just tested the your Drop Downs and found a problem. The string returned by the drop down is a long string with some useless values:
    FRL.Follow, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

    For state I can strip the first value, but for sense it makes no sense, since I need the name and not the type of sense.
    I think booth drop downs should only show what RaptorAI is in the current GameObject, for states, the name of all attached states, and for sense all attached sense names.
     
  37. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hi Franky!
    The string returned is the AssemblyQualifiedName in order to avoid issues when converting from string to System.Type. You can get the name by using
    Code (CSharp):
    1. System.Type.GetType (YOURSTRING).FullName
    Alternatively, I can add a parameter to the attributes that lets you choose between the AssemblyQualifiedName and the actual value displayed (FullName).
     
  38. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Version 2.11 has now been released and is available for download. It includes a few fixes and minor features, along with some useful new waypoint variables. You can check out the changelog and updated documentation on the website.
     
  39. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Hello people!
    It's been some time since the last update, but it is finally here! Version 2.2 is now available and ready to download.
    It includes some cool new features, along with various fixes and improvements. As usual you can check out the changelog at the website.
     
    Last edited: Mar 4, 2019