Search Unity

Dynamic AI Project Help Page

Discussion in 'Community Learning & Teaching' started by brilliantgames, Nov 23, 2012.

  1. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Important note on help questions: I am very busy with many projects, and I run several threads. However, you are far more likely to get a response by simply sending me a PM right here on the Unity forums. Just specify which package and what your problem is.


    Welcome to the Dynamic AI Help Page. This page will give you access to tutorials and downloadable content.

    Main Forum Thread: http://forum.unity3d.com/threads/154639-Dynamic-AI-Project

    Asset Store Link http://u3d.as/content/brilliant-game-studios/dynamic-navigation-beta-/3FZ



    Dynamic Navigation


    Video Tutorial





    ATTENTION PEOPLE WITH FANTASY AI!

    For those of you who own Fantasy AI, you may know this Navigation system is compatible with Fantasy AI! Just simply download the link below and follow the instructions!

    Download Link: https://dl.dropbox.com/u/65183439/Fantasy pluggin/FantasyPlugginPlay.cs

    Fantasy AI Instructions:

    - First you must make sure both Fantasy AI and Dynamic navigation are imported into your project(This is why this script was not included with the package right off the bat, errors would occur from scripts not existing).

    - Now, import the C# script from the download link("Fantasy Pluggin Play").

    - To make the AI use this pathfinding, first remove the old "Navigation" script attached to your Fantasy AI character, as well as the "Navmeshtarget" script.

    - Now add the "Fantasy Pluggin Play" script to your character. Followed by the "GridPosition" "Navigator" scripts included with Dynamic Navigation.

    Thats it! Your character is now ready for Dynamic Navigation.





    Tutorial 1

    In this tutorial, we will go over all the basics to get you started.


    Creating a grid

    1. First you must import Dynamic Navigation into your project.

    2. Now we are going to create a grid. This is simple, first create an empty game object Menu, "Game Object/Create Empty". You should name this appropriately, for your own reference.

    3. Now add the "Grid" script to your empty game object. Menu, "Component/Dynamic Navigation/Grid"

    4. You now have a Grid editor. You should see a white square surrounding your empty game object, this represents the size of the grid you are about to create.




    5. Now we should go over a few of the basic variables before we create a grid.
    Grid Size. This is the resolution of your grid. The default is 100, this means you will have 100x100 nodes in your grid.
    Cube Size. This is the size of each square on the grid, the size you choose, should be completely dependant on the proportion of your world, and the characters in it(If you have a variety of different size characters, you can make multiple grids).

    IMPORTANT: Because of the way the algorithms work, not every cube size is compatible. The way cube size operates is by half's, quarters, eighths and sixteenths. Some examples of compatible cube sizes include, 2, 1.75, 1.5 1.25, 1.125... Lets say you wanted to make a cube size as 1.8, well that is not compatible, but the closest one compatible would be 1.875.


    Step height, is the height in which the grid points will sit off the ground, this does not have a dramatic affect on results, but it can in certain instances.
    Slope height, is the max height a node can be from its neighbour(Basically controls the steepness allowed in the grid).
    Layers, are basically the amout of floors the grid will penetrate. So if you have a 10 story building, you will need 10 layers.
    Layer height, is the minimum height before a new layer(This should be determined by the height of your characters).
    Ignore Collision Layer, is the collision layer that the grid will completely ignore.
    Not Walkable Collision Layer, is the collision layer that you know the AI will never walk on(This could include, boxes, rooftops).
    Dynamic Obstacle Layer, is the collision layer for Dynamic obstacles(Obstacles that may move) that have the dynamic obstacle script attached to them.

    All objects in your scene should be assigned to the appropriate layers. Normal static objects, that can be both walk-able and an obstacle, should not be assigned to any of these. (But you can very well get away without assign objects to any of the layers)

    6. Now that you have determined all of your variables. You can choose to "Create Grid Now".

    If you want to view your grid you can check "Debug Show Connections" as true. To see not walkable grid check "Debug Show Nonwalkable".







    Tutorial 2


    Quick AI and Navigator Setup


    This section we will discuss how to setup a Navigator/AI to navigate the grid you have setup. There is a pre setup AI character in the prefabs folder if you wish to use that one. Although setting up your own simple AI character for pathfinding takes little time.


    1. There are 2 scripts that need to be attached to your AI character in order for the pathfinding to work correctly. These are, "Navigator", and "GridPosition". The Navigator script is in charge of the pathfinding, while the "GridPostion" script is respondisble for locating where the AI is located on the grid with algorithms.
    "GridPosition" is required to be attached to to AI characters, as well as objects that are being target in pathfinding, for the pathfinding to work on both ends.



    2. Now that we have done this, lets attach the simple "AIMove" script that comes with the package(Just so we can get some movement on the path). Feel free to use an animated character, this script supports running and idle animations. To use this make sure to assign the "Character to Animate" as well assign the run and idle animations.

    3. Alright, now our character is ready to pathfind and move around. But, lets take a look at some of the variables in the inspector for "Navigator".

    Grid - This is by far the most important one. You need to assign the grid before anything will work. This is done manually cause of flexibility for switching between multiple grids.
    Debugs Active - This will give you debug messages as well as give you visibility of the A* in action.
    Target - The target the Navigator is currently targeting. This is generally only used when programming your own AI, where you would assign your AI's current target to this.
    Change Node Dist - The distance before the AI will change to the next node on his path. This is dependant on the size of your characters and proportions. Note: The larger the node distance, the more 'relaxed' their pathfinding will look, but too high will give you undesired results.
    Slow To Stop - This is only used when programming your own AI. This is the Navigators way of telling the AI that a path has not yet been made, or there is no path to be found(This was made visible in the inspector to make programming visually easier). When programming your AI, it should be idle when Slow To Stop is true.
    Path Speed - This is the speed that A* search will travel through the nodes. This affects performance the most out of everything. It is important to note, that even a speed of 1 is still usable to many situations Example, if the Path speed was set to 5, that would mean the search travels through 5 nodes per frame.
    Static Path Speed - This is the speed the A* search travels when searching a static target. This can be set significantly higher because generally the path only needs to be calculated once. Targets are set to static through the "Grid Position" script attached to the target.("StaticTarget")
    Max Dist - This is the maximum distance the A* will search will go for. It is important to keep this reasonable, cause if you have a very massive world and your AI cannot find a route to his target, it will continue searching until the maximum is reached or all corners have been searched.
    Smooth Path - When enabled, paths are smoothed. You should always have this on for the best results.
    Show Path - Shows the path of the navigator.
    Navigate Target-This needs to be enabled when your AI is pursuing a target. The only times this should b disabled is when your AI is not pursuing any targets or is in idle.
    Retreat Target - This should be enabled when you want your AI to retreat from his target. Note: This feature is not yet perfected, you may not get the desired results.
    Retreat Distance - The distance you want the AI to retreat.

    4. Alright, now that we have got a basic understand of what the variables do, lets put this to the test! Create a cube, or an empty gameobject and add the "Grid Position" script to it. This is going to be our 'target'. Remember to assign the grid in its inspector.

    It is important to note, in the Grid Position script, the axis height, is the height at which the axis hovers off the ground. This should be set as accurately as possible, in order for the Grid Position script to work as accurately as possible.

    5. Place the target in an area you know the AI can find a route to it.

    6. Now, in the AIMove script, assign the target you made to "Target" in the inspector, and enable "Goto Target". Press play and he should pathfind to the target if everything is set up correctly. :)









    Tutorial 3



    Dynamic Obstacles Navigation Portals


    In this section, we will talk about the two very useful features, Dynamic Obstacles, and Navigation Portals.

    Dynamic Obstacles are objects that will move in your scene. This should never be used for characters because you will likely get undesired results. Dynamic Obstacles should only be used for objects in your scene that either spawn or move. Some examples could be, doors, objects with moveable physics like crates, barrels, even large pieces of debri from an explosion or building collapse.

    Navigation Portals is a feature that gives you the ability to connect any 2 nodes on the grid, and have the ability to have either ends open or closed. This is a very useful feature that many pathfinding solutions lack. Some uses for this may include, doors locked or unlocked, ladders, elevators, jumpable areas, areas too tight for the chosen grid resolution, the possibilities are endless. A word of caution when using this feature though, placing these portals in the wrong areas can result in faulty pathfinding. If you were to place 2 portals in an open area bridging the gap of 2 nodes that are already closely connected, this may cause some strange path patterns or 'dead ends'. You should generally only use portal navigation for nodes that would not otherwise be connected, that is what they are there for anyway.


    Setting up a Dynamic Obstacle

    Setting up a Dynamic Obstacle is very simple. First your object that you have chosen to be dynamic, must have collision setup properly. But dont worry, even mesh colliders work perfectly, without rigid bodies! Once your object is collision ready, simply add the "Dynamic Obstacle" script. The only thing left now, is to choose the grid. Thats it!!

    Note: For dynamic obstacles to work properly, it is required that your axis is located within collision geometry(Preferably the center). The reason for this is, when the Dynamic Obstacle is creating a footprint, it builds from the inside and out like a shock wave. If your axis is located outside of collision geometry, it will start building, and not detect any collision and wont work.




    Setting Up Navigation Portals

    Fastest way to get started, is by going into the Dynamic Navigation Folder, then the prefabs folder, then drag in a the "Portal" prefab. Next you need to assign a grid.


    The purple line represents the current node its closest to.



    Now copy and paste the portal you just made. You may now assign the "Portal Connection". Portal connection is the other portal in which it is connected to, so in this case its the one you just copied off of. The portals must both be assigned to eachother.


    You will see a blue line connecting the 2 portals now.




    Now that they are connected, you need to decide which sides are open(Portal Open). If both sides are checked as "Portal Open", the AI will consider this a valid route no matter where he is. This is great for a case where you want the AI to say, go up and down a ladder, but, if you wanted to make an area where he could jump off, but not try to jump back up, you would then only make the top one "Open Portal".








    Tutorial 4


    Integrating your own AI

    In this section, we will talk about how integrate your own AI with this pathfinding system.


    Integrating your own AI to use the pathfinding is really only a few lines of code. There are a few things that need to be both inputted to the Navigator then outputted back to your AI.

    Lets say, your AI has spotted an enemy. Now we want him to use the Navigator to find a path to his enemy. Heres an example script.


    Code (csharp):
    1.  
    2.  
    3. //WE GET THE COMPONENT OF THE NAVIGATOR
    4. Navigator nav=(Navigator)GetComponent("Navigator");
    5.  
    6. //LETS PRETEND 'ENEMYVISIBLE' IS A BOOL FOR WHEN THE AI HAS SPOTTED THE ENEMY, AND 'ENEMY' REPRESENTS' THE TRANSFORM OF THE ENEMY CHARACTER.
    7.  
    8. if(enemyvisible){
    9.  
    10. //LETS FIRST ASK IF THE NAVIGATORS TARGET IS ALREADY THE ENEMY, SO WE DONT ASSIGN IT EVERY FRAME
    11. if(nav.Target==enemy){} else nav.Target==enemy;
    12.  
    13. //NOW WE MUST TELL THE NAVIGATOR TO NAVIGATE THE ASSIGNED TARGET
    14.  
    15. if(nav.NavigateTarget){} else nav.NavigateTarget=true;
    16.  
    17. //SO NOW OUR NAVIGTOR WILL START CREATING A PATH TO THE ENEMY TARGET.. BUT WE NEED TO MAKE IT SO THE AI WILL ACTUALLY FOLLOW THIS PATH ONCE IT HAS BEEN CALCULATED
    18. //WHERE, "CURRENTTARGETWAYPOINT" IS THE CURRENT TARGET NODE IN THE PATH OF THE NAVIGATOR, AND "CURRENTTARGET" IS GOING TO BE OUR MADE UP TRANSFORM FOR THIS SAMPLE, REPRESENTING THE CURRENT TARGET THE AI IS POINTING TOWARDS, WHICH WILL BE THE DIFFERENT NODES ON THE PATH.
    19.  
    20. CurrentTarget=nav.CurrentTargetWaypoint;
    21.  
    22. //SO FIRST, WE WILL ASK IF "SLOWTOSTOP" IS TRUE BEFORE WE TELL THE AI TO RUN ALONG HIS PATH.  THE REASON FOR THIS IS, WHEN THE NAVIGATORS "SLOWTOSTOP' IS SET TO TRUE, THAT MEANS IT HAS NOT YET FOUND A PATH, OR THERE IS NO PATH.
    23. //WHERE IDLE IS THE STANDING IDLE STATE OF THE AI, AND RUN IS CHARGING/RUNNING ALONG PATH
    24.  
    25. if(nav.SlowToStop){
    26. idle=true;
    27. run=false;
    28. }
    29. else{
    30. idle=false;
    31. run=true;
    32.  
    33. }
    34. }
    35.  
    36.  
    37.  
    Thats it! Those are the basics of using your own AI with Dynamic Navigation. The most important things to remember are, assigning the correct current target of the AI, telling the Navigator to "NavigateTarget" and telling the AI to turn towards the Navigators "CurrentTargetWaypoint". Remember, when "SlowToStop" is true in the Navigator, your AI should not be attempting to move along the path.






    Page Under Construction...
     
    Last edited: Jul 23, 2013
  2. sinstone

    sinstone

    Joined:
    Sep 12, 2012
    Posts:
    4
    I'm a little confused! I've just bought Fantasy AI 2.0 and I've been trying, unsuccessfully, to integrate a FPS player into one of the empty AI prefabs so I can get the characters I've got to attack the player.

    Can I do that with Fantasy AI 2.0 or do I need a different Unity asset?

    I'm trying to create a zombie/skeleton/etc shootem' up game rather than a 'fantasy' sword play type game.
     
  3. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    This isnt a Fantasy AI forum.. But all you need for the AI to attack any object, is a health script, team script, and the correct collision layer(Layer 9). Also keep an eye on where the axis is positioned on your player, if its on the ground its likely their raycasting vision could be obstructed. You should visit the Fantasy AI help page...

    http://forum.unity3d.com/threads/129422-Advanced-Fantasy-AI-Tutorials
     
  4. sinstone

    sinstone

    Joined:
    Sep 12, 2012
    Posts:
    4
    Thanks for the quick reply.

    I'm using the Ultimate FPS Camera asset for now which isn't quite compatible with Fantasy AI so I've had to add a 'Damage' method to your health script and change the way the projectiles work but I've got everything working now :)

    Cheers
     
  5. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Awesome. Just so you know, Dynamic Navigation is now released! Its compatible with Fantasy AI out of the box.

    Asset Store: http://u3d.as/content/brilliant-game-studios/dynamic-navigation-beta-/3FZ
     
  6. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    I have just bought this, but problem is, i'm using your default map with my fps player and a enemy model, the enemy comes towards me, but if i go round a corner he start glitching out and running backwards and forwards. Why?
     
  7. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Did you add a 'gridposition' script to your player/target? Also, when you have added the 'grid position' script to your player or target. You have to make sure the 'axis height'(pivot point) is correct. So if your 'axis height'(pivot point) on your player or target is right at his feet, you would want the axis height to be set to 0, because it is 0 meters above the ground. Hope this makes sense.

    Edit: If you want to measure your axis height. Simply place your players feet at ground level, then take note of your y position. Then select your character and move him down on the y axis until the pivot point is level with the ground. Subtract your previously noted y position with the current one and that is how high your 'axis height' is. :)
     
    Last edited: Dec 9, 2012
  8. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Last edited: Dec 9, 2012
  9. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    If you are getting red you likely have a collider somewhere... Also did you read about cube sizes? Not every cube size is compatible because of how the algorithms work. Also your capsule size should be around the same size as your cube size.(Generally a little smaller)
     
  10. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    I added some pics to the post :/
     
  11. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Looks fine to me.. Your cube size is waaay too large though. Make your cube size smaller. If you need to go smaller than 1, use 0.75 or 0.5 or 0.25. Make sure to match all the other numbers with it.

    I will quickly explain why your characters run in circles. The grid position does not allow you to connect with a nonwalkable area.. If you enter a nonwalkable area, the AI will go to the last walkable area your player/target was. They walk in circles because they have reached the goal waypoint, but are not close enough to the target to stop. This will be fixed by making a more detailed grid by making the cube size smaller.

    Each square on the grid should be around the width of the AI characters themselves. This makes sense because this will allow them to enter more areas they can logically fit in, like a doorway or slim hallway.
     
  12. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    I am proper struggling with this, maybe i don't fully understand how these values work, etc.

    Is there a way for you to have a look and let me know? Just so i get a understanding of this?
     
  13. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Just make your cube size smaller. Match the capsule size to the cube size.. Mess around with all the variables to get a feel for it. I gave definitions for every Variable in there.
     
  14. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Ok, i think i got it now, i will let you know how i get on :D
     
  15. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    This is my AI Move script, based on the one you provided, how would i get the enemy to look at the player at all times? They sometimes hit me whilst facing the wrong way :(

    http://paste.thedigitalboard.com/index.php/view/89109431
     
  16. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Are they zombies?

    Just make him turn towards his "Target" when he is attacking....

    Code (csharp):
    1.  
    2.  
    3. IEnumerator DoAttack(){
    4. transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Target - transform.position), 7 * Time.deltaTime);
    5. }
    6.  
     
  17. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Yh there zombies :D and thanks
     
  18. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
  19. maidamedia

    maidamedia

    Joined:
    Nov 19, 2009
    Posts:
    224
    That's what I was waiting for!!! Very nice tutorial, Robert. Thanks so much:D:D:D
     
  20. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    I've got a large map. I'd like to have either a grid that covers the whole map (i think too slow) or multiple grids that make up the map. If I use multiple grids, how do I make the AI use the extra grids? I've tried making them children of the original grid but the AI gets stuck at the border of the grid which is unwalkable by default.

    2 Weeks Later, no reply. Thanks.

    I have a new issue ontop of the existing issue. New project, new scene, setup the same. Nothing moves... All the navigation settings are the same. The only difference is that the character is walking on a plane instead of a terrain object. The grid is walkable but the path shows up red instead of green. I'll keep trying to work it out but it'd be nice with some debugging that actually did something for example. Why does my AI not move? Trying to move...position not changing...please check this or that. I click 'debugs active' and the only debugging it gives me is 'grid created' which is the least helpful of any debugging. Not trying to be a dick, I paid money for this software because it looked like it worked smoothly but really, this software has a small margin for error and it does not tell you where the error is.

    --Tried it with a terrain object still nothing moves. I get the error:

    Path Failed
    UnityEngine.Debug:Log(Object)
    Navigator:Update()

    Edit: Resolved the 'objects not moving' error. The position of the target was too far from the nav mesh however in the past this was never an issue. Making a new empty game object as a target at the same height seemed to work.
     
    Last edited: Jan 12, 2013
  21. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Have you tried using one grid? The size of the grid has almost no affect on performance, only memory. The only thing that can affect performance is having many layers.

    As for having multiple grids. There is no out of the box working solution for having AI actually use multiple grids and transferring between them. What you could do, is have the grids significantly overlap eachother and have the AI constantly use the grid that is closest to him.
     
  22. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Check the next page, I did respond to this. But now I see a massive edit. Sorry I don't visit this page often(Most questions are asked on the main thread). If your AI are not moving towards their target, it can be a number of things. You said the path was in red..? The red line indicates what node he is closest to, it is not a path.. If this red line appears long and not pointed to a node at his feet, then this means his Axis Height is likely not set correctly(Axis height is already non existent for the next update, it will be automatically determined).

    Another reason for AI not moving could be his maxdist. This is the max distance he will search for a path. And finally, if there is no way to get to a target, you will get "Path Failed".

    I have noticed your review on the Asset Store. Is that yours? I apologize for your frustration, but there are some things said in there that are very unprofessional. This product is still in beta, as advertised. As well there is no false advertisement in this product. I am currently working on the next update and many bugs have been fixed, as well as more features being added. I would like to kindly ask that you either remove that review until the full version is released, or change it to be more professional and reasonable.

    Thank you,

    Rob.
     
    Last edited: Jan 13, 2013
  23. Shintaja

    Shintaja

    Joined:
    Jan 13, 2012
    Posts:
    15
    Hey, I've added a grid to one of my scenes (yes the grid is functioning properly) and I've got some cars spawning around the map. I add in Start function the DynamicObstacle component to these cars and set the grid for the component, but every car gives a nullreference error which is in DynamicObstacle update function, which I can't go see whats wrong because it's in a dll.. (If I manually activate the DynamicObstacle it does not give me any nullreference error but this is not a solution).

    For what reason does this happen and how do I fix it?

    Thanks.
     
  24. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Are you sure you are assigning the right grid object..? You shouldn't get any errors period, even if you don't even have a grid assigned. The only way you would be getting that error is if you were assigning an object that doesn't have the grid script attached..
     
  25. Shintaja

    Shintaja

    Joined:
    Jan 13, 2012
    Posts:
    15
    Yes, I'm sure, as I add the DynamicObstacle through AddComponent to the vehicle and then disable the DynamicObstacle and give the grid gameobject to said DynamicObstacle.

    Code (csharp):
    1.  
    2. void Awake ()
    3. {
    4.     gameObject.AddComponent<DynamicObstacle>();
    5.     GetComponent<DynamicObstacle> ().enabled = false;
    6.     GetComponent<DynamicObstacle> ().Grid = GameObject.Find("Grid");
    7.     Invoke("setActive", 2f);
    8. }
    9.  
    And just to make sure it gets the Grid I added the invoke which calls the following function:

    Code (csharp):
    1.  
    2. public void setActive ()
    3. {
    4.     if(GetComponent<DynamicObstacle> ().Grid)
    5.         GetComponent<DynamicObstacle> ().enabled = true;   
    6.     else
    7.         Debug.Log("missing gameobject.");
    8. }
    9.  
    If I don't call the setActive and I just manually check the DynamicObstacle to be activated through the inspector, the grid would start then working properly but not when I activate it through code. (Just to make it clear: the Grid gameobject is there and it IS correct for each vehicle because when I do check the enable box in DynamicObstacle it works without me manually adding the Grid to each DynamicObstacle).

    It seems that If I add the DynamicObstacle through a script and activate it, it won't work expect if I manually activate it.

    I also tried to add the DynamicObstacle during runtime manually also added the grid manually, and it worked.

    I also tried to add the DynamicObstacle from hierarchy to the vehicle before runtime and then through code add the grid to the DynamicObstacle and it worked.

    Seems the problem is that when you try to add the DynamicObstacle to an object via code during runtime, it will not work.

    EDIT:

    Seems like if you add any of the Dynamic Navigation scripts to a object during runtime results in this "awesome" NullReferenceExpection.

    Example: (I didn't do anything expect add the component through script, I also added the same component from inspector to another vehicle and that works....)
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. GridPosition.Update ()
    4.  
    This has to be fixed.

    Thanks.

    EDIT 2:

    I just created an empty gameobject and added the GridPosition component through a script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class somethingawful : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         gameObject.AddComponent<GridPosition> ();
    10.     }
    11.    
    12. }
    13.  
    This gives me:

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. GridPosition.Update ()
    4.  
    ´

    I also tried to add the component manually which seems to work... but it's not an option for us.
     
    Last edited: Jan 18, 2013
  26. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Sorry about the delay I have barely been around the house much.

    I'm really not sure about the methods in which you are going about this..

    This is how I would do this. Instead of adding the Dynamic Obstacle script through scripting, just have it already attached to your car prefab in your project folder.

    So whatever object your instantiation script is attached to put this. You should have the grid object already assigned to your public Transform var. Its really simple stuff.


    Code (csharp):
    1.  
    2.  
    3. //HERE IS THE CAR YOU ARE INSTANTIATING
    4. public GameObject Car;
    5.  
    6. //HERE IS THE GRID OBJECT THAT NEEDS TO BE ASSIGNED WHEN THE CAR IS INSTANTIATED
    7. public Transform Grid;
    8.  
    9. //IM JUST PUTTING THIS AT THE START AS AN EXAMPLE, I DONT KNOW WHAT YOUR INSTANTIATE CODE IS
    10.  
    11. void Start () {
    12. //CAR INSTANTIATES
    13. GameObject NewCar= (GameObject)Instantiate (Car, transform.position, transform.rotation);
    14. //GET COMPONENT FOR GRID SCRIPT
    15. DynamicObstacle DynObScript=(DynamicObstacle)NewCar.transform.GetComponent("DynamicObstacle");
    16.  
    17. //ASSIGN GRID.  THATS IT!
    18. DynObScript.grid=Grid;
    19.  
    20.  
    21.  
    22. }
    23.  
    24.  
    25.  
    26.  
    27.  
    28.  
    29.  
    30.  
     
  27. Solidust

    Solidust

    Joined:
    Nov 19, 2012
    Posts:
    15
    I am having exactly same problem as Shintaja... :(
     
  28. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Hmm, well I'll look into it and see if there is some sort of bug that I am not aware of. :)
     
  29. Solidust

    Solidust

    Joined:
    Nov 19, 2012
    Posts:
    15
    Okay thank you :) Any ETA?:p

    And another Question, can you add new method that uses courotine to update grid?? I would love to see that!
     
  30. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    I tested adding dynamic obstacles. No problems at all. All you have to do is simply add the grid Transform to the dynamic obstacle grid. Even if you don't add a grid, it is designed not to have any errors. The only way you can get an error is if you assign an object that does not have a grid script attached... Not sure what else to say, hope you resolve the problem.
     
  31. Shintaja

    Shintaja

    Joined:
    Jan 13, 2012
    Posts:
    15
    So you did not try to test it by adding the dynamic obstacle component through scripting? Do you not realize that we have a lot of prefabs and not to mention assets which users have created and then added to the game which are not present for the developers, so again I'll say it, it is NOT possible for us to add the component directly from inspector to the prefab.
     
  32. Solidust

    Solidust

    Joined:
    Nov 19, 2012
    Posts:
    15
    brilliantgames is it possible to add courotine function to the update grid now? If not, can you add that possibility?
     
  33. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Okay apologies, so when I first tested, I was testing with the DynOb script already attached, then assigning the grid through script, and it worked fine. Then I did try adding the component through script and it does get the error you described.. It actually makes no sense that this would happen. I'm actually wondering if this is a Unity bug.. I will investigate this. I apologize for any inconvenience.



    Edit: So I did some more research into this problem, and it turns out, when you add a script through the editor, there's actually a few things Unity engine does for you. But if you add a script through another script, things like lists wont properly be initialized by a constructor. I'm glad I looked into this, because this is something I was completely unaware of.

    This will be fixed in the next update which I hope to release soon. Have a nice day everyone. :)
     
    Last edited: Jan 25, 2013
  34. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Well is it not already simple enough? CreateGirdNow=true;
     
  35. Solidust

    Solidust

    Joined:
    Nov 19, 2012
    Posts:
    15
    but if i have big grid it lags, i want a possibility to control execution time... you know like StartCourotine(UpdateGrid).
     
  36. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Yeah I am planning to implement a feature to gradually build the grid.
     
  37. unitylover2012

    unitylover2012

    Joined:
    Oct 7, 2012
    Posts:
    12
    How easy would it be to implement this with RAINONE?.

    Thanks
     
  38. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    I have not used RainOne. But the first pages shows how to integrate this with your own AI through script. Super simple stuff. :)
     
  39. unitylover2012

    unitylover2012

    Joined:
    Oct 7, 2012
    Posts:
    12
    LOL super simple IF you are a programmer :p

    Thats why I use RAINONE cus I aint no programmer :p

    Thanks will look at first page again
     
  40. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    Is there a new version out yet? I have a version from December 2012 when i first bought it via gameprefabs.com

    for proof of purchase

    Thanks
     
  41. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    You will get an email when the update is released. It is not yet. Soon though. :)
     
  42. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    ok, have you managed to reduce memory usage and speed up debug lines in the editor?
     
  43. Insanity-Matters

    Insanity-Matters

    Joined:
    Feb 16, 2013
    Posts:
    12
    Probably not the right place for this but i cant figure out how to PM you. I have just bought Fantasy AI Pack (Thinking it was a quick solve to my dynamic path finding. Turns out i was quite wrong and i have bought completely the wrong asset. I dont suppose you have any idea how i could return the asset or swap it? Also could you add to your fantasy AI asset page "This PACK does not include the dynamic path finding code showcased with it on youtube"

    Refer to your official video
    http://www.youtube.com/watch?v=eKhVBT5zcfE 1 min 28 seconds in.

    This is VERY misleading. I have to say the product is great but its not the one i was lead to believe it was by you marketing. Thus its not fit for purpose.
     
  44. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    I really can't use this atm as it uses WAY to much memory and slows my Unity IDE down really bad when i generate a grid. I should easily be able to generate a decent size grid (400x400) with a capsule size of 0.45 and a cube size of 0.5. If i make the cube size any bigger, then i get the issue where i can stand against a wall and the enemies do not come after me. Unless you know of a way to fix this, it would be good as i wont need such a big grid as the cube size would be bigger.
     
  45. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    What kind of colliders are you using on your walls? If there is any hollow space in your walls, its possible that the grid position script is connecting with a grid point inside the wall. If you make sure to have solid colliders on your walls this should never happen. The only time an AI will not find a path, is if there is no physical way of getting there according to the relative grid position(Or if the target is out of range). Hope this helps.
     
  46. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    i mainly use box colliders as opposed to mesh colliders, the main thing is if i try to show the grid in debug mode, my unity editor freezes/slows down so i am finding it hard to debug.

    Also i keep getting issues like this and i can't work out what is causing it



    Also is it possible to have more ignore layers? For things like Debris? etc
     
    Last edited: Feb 19, 2013
  47. Durston88

    Durston88

    Joined:
    Mar 15, 2012
    Posts:
    110
    Hey there. Picked this up a few weeks ago after sending you a PM, just got around to using it yesterday and today. Loving it so far! I was wondering if there was any documentation or more scriptable functions that could be used. The script(s) are in a dll so can't really go in there to have a look.

    Right now I'm just wondering if there's a way to navigate to a Vector3 position. Would be nice if I could do something like

    nav.CurrentTargetWaypoint = new Vector3(x,y,z);

    instead of having to make a new empty gameobject and attach the Grid Position script to it. I'm currently thinking of doing this to script in a Retreat ability, partly to have control over where it retreats to and also because the standard Retreat bool doesn't seem to work all that well yet.

    Anyway, just wondering if there's a simple way like that or if I need to create a new gameobject with that script every time I want to retreat. Thanks.
     
  48. milox777

    milox777

    Joined:
    Sep 23, 2012
    Posts:
    195
    I'm having a huge problem with Dynamic Navigation on iOS devices. Basically, Grid.Update() process is taking a lot of CPU resources basically killing the framerate - even more than Render process which is usually taking the most. I'm 100% sure that this is specifically the Grid script responsible for this, when I disable it everything goes back to normal. My grid is nothing fancy, map is pretty small too, I have only two enemies (powered by fantasy AI) and it's basically unplayable when I turn on the grid.

    EDIT: It seems that this happens everytime I add something like a Navigation portal or a target for Fantasy AI character to go to with GridPosition script attached to it. Then the CPU usage increases dramatically even on a PC, and mobiles it drops below 15 fps. Now if I remove all nav portals and target cubes and recreate the grid it seems to be working OK, but not always. I'm really confused with this...

    EDIT2: It seems that I've found the final solution - don't enable Debug show nonwalkable/connections when you build for mobiles. That's what responsible for slowdown. Which is odd because when you play the build on a device you don't see the grid, but it seems that enabling debug and leaving it causes dramatic resource use increase. You should really warn about this in the documentation...

    $profiler.png $grid.png
     
    Last edited: Mar 5, 2013
  49. Cathei

    Cathei

    Joined:
    Dec 18, 2012
    Posts:
    7
    I have some problem that Navigator says 'IndexOutOfBounds'
    Can you tell me exactly when that exception pop out?

    By the way, Is there no plan to change type of layer masks like "Ignore Collision Layer" int to LayerMask?
     
  50. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    good luck getting a response, this asset is buggy as hell. Nothing but trouble with it.