Search Unity

[RELEASED] SAP2D System 1.1 (FREE Astar Pathfinding for 2D games)

Discussion in 'Assets and Asset Store' started by MiSchneider, Apr 7, 2018.

  1. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Yes, you shuould use two ortagonal axises x and y.
     
  2. Isaqee

    Isaqee

    Joined:
    Apr 9, 2020
    Posts:
    1
    MiSchneider, we are stuck at this.



    Enemy doesn't know how to get to us and go around obstacles. We need help. Can u give us some directions please? We can provide more info if needed. Thank You.

    Edit: Also, we want to change the SAP2D grid to fit out isometric grid. Can you help us with that too? Thank you again.
     
    Last edited: Apr 25, 2020
  3. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Try to decrease tile diameter parameter of your grid. It's will help to calculate your colliders correctly. Maybe agents walk through unwalkable areas.
    Unfortunately, isometric grids are not supported yet.
     
  4. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    This looks like a really great asset especially for 2D pathfinding and the only one I could find that can optionally disable diagonal movement. I just wanted to say great work @MiSchneider! I really hope you can continue to support this even if you start a Patreon or something to make more worth your time.
     
    MiSchneider likes this.
  5. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Thanks. You could write a review and share this asset with your friends. It is the best support for me now.
     
  6. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I certainly will. Thank you!
     
  7. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Alrighty, so I just imported into a new project that I am working on. Sorry to bother you but I am getting some errors running the demos - demo 1, for example. I am on Unity 2019.3.11f1.

    The errors in the console are as follows:

    Component GUI Layer in Main Camera for Scene Assets/SAP2D/Resources/Demos/Demo_Dynamic_Obstacles/Demo 1.unity is no longer available.
    It will be removed after you edit this GameObject and save the Scene.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Component at index 2 could not be loaded when loading game object 'Main Camera'. Removing it!
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Path not found
    UnityEngine.Debug:LogError(Object)
    SAP2D.SAP2DPathfinder:FindPath(Vector2, Vector2, SAP2DPathfindingConfig) (at Assets/SAP2D/Resources/Main/System/SAP2DPathfinder.cs:95)
    SAP2D.<FindPath>d__20:MoveNext() (at Assets/SAP2D/Resources/Main/System/SAP2DAgent.cs:108)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    SAP2D.<FindPath>d__20:MoveNext() (at Assets/SAP2D/Resources/Main/System/SAP2DAgent.cs:113)


    Sorry for the bother but I am happy to fix it myself if you can point me in the right direction. :)
     
  8. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    The latest build was on the Unity 2019.2.0 version. I recommend to use it until I will release a new version.
     
  9. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Sounds good. Just for interest sake and not to be a bother but any roadmap timeline for 2019.3 support? Thanks again.
     
  10. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    Hi! It is definitely the best grid system for 2D games. Super simple to use, very efficient. I loved it. And I have 3 grid systems, I'll keep this one.

    I just wanted to report that sometimes I get this error in UNITY 2019.3.14f1

    Instance of SAP2DPathfinderEditor couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets / Editor folder

    And with the dynamic obstacle too...
    Instance of SAP2DDynamicObstacleEditor couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.


    .
     
    Last edited: Jun 3, 2020
  11. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    In addition when this error come, I see this "Multi-object editin not supported" (But I just only select oneobject)
    upload_2020-6-3_23-52-58.png
     
  12. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    How many instances of SAP2DPathfinder do you have in your scene?
     
    gferrari likes this.
  13. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    Hi! I have just one. It happend very frequent I don't know how to reproduce it.

    upload_2020-6-4_17-23-54.png
     
    Last edited: Jun 4, 2020
  14. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    gferrari likes this.
  15. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    Thanks! In the actual new update of Unity3D it work better (I have less this bug), but I think they don't patch it.
    I have another question,I actually need a suggestion about how I could avoid the overlap my agent objects when they try to catch the target. I don't want to use Rigibody2D. Do you have some idea or something to start?
    upload_2020-6-8_22-8-34.png
     
  16. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Probably you should change the behavior of your agents. I think that the easiest way to do this is to check tiles for other agents (checking any colliders in a single tile) and make something like a queue. Remember that you have a full path to the target and you can stop the agent if the next point contains other agents;
     
    gferrari likes this.
  17. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    I am very happy with this Asset. Is incredible. Thank you!

     
  18. NainBR

    NainBR

    Joined:
    Apr 13, 2020
    Posts:
    2
    Hello. Are we allowed to use this asset on comercial products?
     
  19. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Yes, this asset promoting with a free license.
     
    gferrari likes this.
  20. Quegg

    Quegg

    Joined:
    Mar 1, 2018
    Posts:
    8
    Hi, i started using this asset for a 2d point and click game, and it performs very well. But recently i got the problem that, in the editor, the grid is not shown. I can sometimes still edit the grid, sometimes not. But the pathfinding still works. When i create a new grid, it is working. Does anyone has an idea how to fix this?
     
  21. Lazy_Sloth

    Lazy_Sloth

    Joined:
    Apr 3, 2018
    Posts:
    39
    Hello! I just found your SAP2D project and I really like it, it's so simple! Very good job, thank you!

    Little notice/suggestion:
    I'd appreciate if you can add an "agent avoidance" function. You know if I have multiple agent/character/enemy then they should avoid each other during the path to make it more realistic. At this moment if I have more than one agent and they get the same target, they "melting" together. Also they occupy the same position after reach target (they should stop past to each other).

    Is there any solution already? Thanks!
     
    Last edited: Aug 5, 2020
  22. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Thanks for your feedback. I will add this feature to my task list.
     
    Last edited: Aug 18, 2020
  23. epoHless

    epoHless

    Joined:
    May 1, 2020
    Posts:
    6
    Hi, before asking if you could help me solve my problem I'd like to thank you very much fpr the free asset, it's been very helpful to me :)

    Now, i have this player and enemy that are prefabs and upon lauching the game those are instantiated inside my random generated dungeon. My problem is that i can't figure out a way to pass the intantiated player's transform to the instantiated enemy to make him follow him.
     
  24. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    I think you should immediately attach a player's transform to your agent (use SAP2DAgent.Target property to do this) after prefabs are instantiated.
    I suppose you can write something like this:

    Code (CSharp):
    1. SAP2DAgent enemy;
    2.  
    3. enemy.Target = Player.transform;
     
  25. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    Hi! When I change settings from my Grid Editor windows and I open my project again the settings back to default again (Colors). I´m using Unity 2020.1.4f1c1 (But I have this problem in previous versions)
    I will keep saying your asset is so easy to use! thanks again. Please if you could make some updates I will very gratefull.

    upload_2020-9-11_0-12-4.png .

    upload_2020-9-11_0-12-4.png
     
  26. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Thanks for feedback. This is a quick fix for this issue. You should add some code lines to DrawGeneralSettings() method of the SAP2DGridEditorWindow script.
    Code (CSharp):
    1.  private void DrawGeneralSettings()
    2.         {
    3.             GUI.skin = null;
    4.  
    5.             GUILayout.BeginArea(new Rect(5, 55, position.width - 10, position.height - 55));
    6.             EditorGUILayout.BeginHorizontal();
    7.             EditorGUILayout.LabelField("Editor Settings", "FlatLabel", GUILayout.MaxWidth(146));
    8.             SAP2DEditorSettings editorSettings = (SAP2DEditorSettings)EditorGUILayout.ObjectField(pathfinder.EditorSettings, typeof(SAP2DEditorSettings), false);
    9.             if (editorSettings != pathfinder.EditorSettings)
    10.             {
    11.                 Debug.Log("d");
    12.                 pathfinder.EditorSettings = editorSettings;
    13.                 EditorUtility.SetDirty(pathfinder.EditorSettings);
    14.             }
    15.             EditorGUILayout.EndHorizontal();
    16.             EditorGUILayout.Space();
    17.             if (pathfinder.EditorSettings != null)
    18.             {
    19.                 EditorGUILayout.TextField("Grid Data Folder Path", pathfinder.EditorSettings.UserDataFolder);
    20.                 Color gridColor = EditorGUILayout.ColorField("Grid", pathfinder.EditorSettings.gridColor);
    21.                 if (gridColor != pathfinder.EditorSettings.gridColor)
    22.                 {
    23.                     pathfinder.EditorSettings.gridColor = gridColor;
    24.                     EditorUtility.SetDirty(pathfinder.EditorSettings); //add this line
    25.                     SceneView.RepaintAll();
    26.                 }
    27.  
    28.                 Color obstacleColor = EditorGUILayout.ColorField("Obstacles", pathfinder.EditorSettings.obstacleColor);
    29.                 if (obstacleColor != pathfinder.EditorSettings.obstacleColor)
    30.                 {
    31.                     pathfinder.EditorSettings.obstacleColor = obstacleColor;
    32.                     EditorUtility.SetDirty(pathfinder.EditorSettings); //add this line
    33.                     SceneView.RepaintAll();
    34.                 }
    35.  
    36.                 Color selectingColor = EditorGUILayout.ColorField("Selecting", pathfinder.EditorSettings.selectingColor);
    37.                 if (selectingColor != pathfinder.EditorSettings.selectingColor)
    38.                 {
    39.                     pathfinder.EditorSettings.selectingColor = selectingColor;
    40.                     EditorUtility.SetDirty(pathfinder.EditorSettings); //add this line
    41.                     SceneView.RepaintAll();
    42.                 }
    43.             }
    44.             GUILayout.EndArea();
    45.         }
     
    gferrari likes this.
  27. pencilking2002

    pencilking2002

    Joined:
    Sep 30, 2013
    Posts:
    23
    Hi there. Thanks for the cool plugin!
    I have a couple of questions:

    1) In my game I have some curvy roads, here's an example of what I mean. Is there a way to smooth out the movement/rotation of the agent so that it fits more with the organic aesthetic of this rather than the more angular/geometric movement?

    2) I noticed that currently the agent tries to find the fastest route to the target, is there a way to make the AI dumber and and not take the shortest path? So for example, I've shaped a "road" with a polygon collider2D and I'd like the agent to be walking in the middle of the road.

    If this plugin isn't good for my use cases, I'm open to suggestions. Thanks!
     
  28. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Hello, thank you for this great asset!

    I was able to improve performance by changing some Lists to Hashsets if you're interested:

    In SAP_GridSource.cs:

    Code (CSharp):
    1. List<SAP_TileData> openList = new List<SAP_TileData>();
    2. List<SAP_TileData> closedList = new List<SAP_TileData>();
    3.  
    4. to:
    5.  
    6. HashSet<SAP_TileData> openList = new HashSet<SAP_TileData>();
    7. HashSet<SAP_TileData> closedList = new HashSet<SAP_TileData>();
    Code (CSharp):
    1. private SAP_TileData FindNextTile(List<SAP_TileData> openList)
    2.  
    3. to:
    4.  
    5. private SAP_TileData FindNextTile(HashSet<SAP_TileData> openList)
    Code (CSharp):
    1. SAP_TileData result = openList[0];
    2.  
    3. to
    4.  
    5. SAP_TileData result = openList.First();
    And don't forget to import LINQ:
    Code (CSharp):
    1. using System.Linq;
     
  29. BluezamX

    BluezamX

    Joined:
    Mar 30, 2018
    Posts:
    9
    Hi, is there a way to increase the agent "size"? Currently the agent tries to move through spaces where the object's own boxcollider2d is too big to fit through, resulting in it bouncing against the walls. Is there a way to increase the agent size so it better avoids these things?

    Also, the SAP2DAgent originates from the center of the gameobject. I could of course make it a child of the player, but I'd rather be able to adjust the offset. Is this possible at the moment?
     
    Last edited: Jan 25, 2021
  30. somanek1976

    somanek1976

    Joined:
    Dec 17, 2023
    Posts:
    1
    Hi.
    "SAP2D Pathfinder hasn't none grids" , But grid is added. What I forgot? Please help!