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


    The SAP2D (Simple A * Pathfinding 2D) path search system is based on Astar algorithm – the shortest path between two points. This search system path you can use to write your own artificial intelligence systems that will help you implement enemies or a system of controlling a character in your 2D game.

    The system is very simple, so if you are not an advanced Unity user, you can easily and fast set up the SAP2D system.



    Also SAP2D System can be used in a 3d games. For example a GPS Navigation in your car like in a gta:

    SAP2D Features:
    - 2D Physics support
    - Manual Obstacles Editing
    - Dynamic Obstacles support
    - Built-in AI

    Assets Store Page
    Online Documentation
     
    Last edited: Apr 17, 2019
    mgear likes this.
  2. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Dynamic obstacles in SAP2D works not pretty nice, because the latest SAP2D build was in a Unity 5.2.5, composite colliders 2D was included in 5.6 version. But, you can fix it. To put simply you can add dynamic obstacle component in a base object wih composite collider component and add dynamic obstacle component in a children objects, also change them colliders to composite collider in a Coll 2D field in Dynamic obstacle script.

    This procces will fixed in the next SAP2D version.
     
  3. unity_ij-uBygkHoAdhw

    unity_ij-uBygkHoAdhw

    Joined:
    Oct 15, 2018
    Posts:
    3
    @MiSchneider In this system, is there a way to set waypoints in a larger map via clicking?
     
  4. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Can you describe your question more detail? In this version the path calculates as a array of vectors. You can write your own script with placing waypoints by cliking and call FindPath method to calculate path to them (as movement in Dota 2). Did I understand you correctly?
     
    Last edited: Nov 23, 2018
  5. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    Hi, this project is alive? thanks
     
  6. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Of Course, I really work hard to release new version. Soon I post some spoilers about it, I hope... -_-
     
    gferrari likes this.
  7. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    SAP2D 2019.1b allows you to comfortably work with large pathfinding grids due to draw optimizations solutions. It means that SAP2D pathfinding system can be used in games like a Rimworld and etc, where your agents uses big map to find path. I think that awesome!

    For example I have 1000x1000 grid (1 million tiles)

     
    Last edited: Jan 27, 2019
  8. lLcrowe

    lLcrowe

    Joined:
    Sep 12, 2017
    Posts:
    7
    Honeycam 2019-02-12 19-15-14.gif What do you think of this bug?
    The purple square is a dynamic obstacle.
    The player has rigid body 2D, one call rider and code.
     
  9. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    It happened, because of dynamic obstacle calculation. The player moves very fast and dynamic obstacle doesn't calculate collisions in time. Try to add any tag to the player and also add this tag to Ignore Collision Tags list in the SAP2D Manager. It will help you.
     
    lLcrowe likes this.
  10. lLcrowe

    lLcrowe

    Joined:
    Sep 12, 2017
    Posts:
    7
    oh. Thanks. I solved it.
     
  11. Sicario7

    Sicario7

    Joined:
    Mar 3, 2019
    Posts:
    5
    I really like your path finding system! I have one question though. How would I make AI jump over obstacles? If you could help it would be greatly appreciated!
     
  12. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Thanks. So... It's very difficult to calculate how AI will jump according with finded path. It is possible if your obstacles have fixed height. Maybe anybody will find a solution to calculate height of each obstcale and change the jump angle in realtime. I think that creating of jumping AI is unpossible with dynamic obstacles. I wrote some code to try to create jumping AI. I'm sure there is a more performant solution.

    You can write me your email if you want this project with my solution.
     
  13. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39

    [04.15.2019] SAP2D 2019.1.2b Update
    :
    - Added multigrid support.
    - Added big grids drawing optimisations.
    - Added new tool for manual obstacles editing mode.
    - Added API optimizations.
    - Added SAP2D About window.
    - Optimized pathfinding core.
    - Ignore Obstacles list changed to Obstacles Layer parameter.
    - Ignore Coners parameter changed to Cut Coners parameter.

    - Updated SAP2D Manager script.
    - Updated SAP2D Dynamic Obstacle script.
    - Updated Documentation.
    - Updated manual obstacles editing panel. Unwalkable tiles which placed by user saves in single scriptable object on User Data folder.
     
  14. gferrari

    gferrari

    Joined:
    Jan 14, 2015
    Posts:
    135
    I have another question. Can I use the Super Tile Map Asset with this? I think you asset is the best path finder 2D but I want to use with Super Tile Map Editor. Thanks!
     
  15. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    I think its possible. Super Tile Map Editor uses square tiles too and you can create new grid in SAP2D Manager and set tile size according with tile size in the Super Tile Map Editor. Its very inportant to find correct path. But of course you can do this in 2D space only.
     
    gferrari likes this.
  16. kkmjnh11110

    kkmjnh11110

    Joined:
    May 9, 2019
    Posts:
    3
    Is the new version of "rubber" not working properly?
    The information in "UserGridData" cannot save "rubber".
     
  17. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Oh.. I understood the problem. I fix some code in UserGridData script. Now it works right. Thanks




    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. namespace SAP2D {
    5.  
    6.     public class SAP_UserData : ScriptableObject
    7.     {
    8.         [HideInInspector]
    9.         public List<SAP_TileData> UnwalkableTiles = new List<SAP_TileData>();
    10.  
    11.         public void AddData(SAP_TileData tile)
    12.         {
    13.             for (int i = 0; i < UnwalkableTiles.Count; i++)
    14.             {
    15.                 if (UnwalkableTiles[i].x == tile.x && UnwalkableTiles[i].y == tile.y) return;
    16.             }
    17.             UnwalkableTiles.Add(tile);
    18.         }
    19.  
    20.         public void DeleteData(SAP_TileData tile)
    21.         {
    22.             for(int i = 0; i < UnwalkableTiles.Count; i++)
    23.             {
    24.                 if(UnwalkableTiles[i].x == tile.x && UnwalkableTiles[i].y == tile.y)
    25.                 {
    26.                     UnwalkableTiles.RemoveAt(i);
    27.                     break;
    28.                 }
    29.             }
    30.         }
    31.     }
    32. }
     
  18. kkmjnh11110

    kkmjnh11110

    Joined:
    May 9, 2019
    Posts:
    3
    thanks for your help!
    A new problem occurred after adding two “grid”.
    Can't edit pathfinding.
     
    Last edited: Jun 18, 2019
  19. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    What do you mean?
     
  20. kkmjnh11110

    kkmjnh11110

    Joined:
    May 9, 2019
    Posts:
    3
    A new problem occurred after adding two “grid”.
    I can't edit the pathfinding grid and store multiple "grid" messages.
     
  21. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Try to rename the second grid and select this grid in dropdown list on the tools panel. The names of grids should be different.
     
  22. krkim_unity

    krkim_unity

    Joined:
    Mar 30, 2018
    Posts:
    5
    I have a question.
    I want to create multiple grids. And can you find the way, regardless of the grid?
     
  23. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    You mean add new grid in SAP2D Manager via custom script?
     
  24. krkim_unity

    krkim_unity

    Joined:
    Mar 30, 2018
    Posts:
    5
    I understand that you can add multiple grids to the SAP2D Manager by looking at the photos of the posts you asked above.
    For example, suppose you have arranged four grids as squares (the boundaries are in contact with each other)
    Then, in the ideal situation, is it only a path finding from each grid? if not
    Does it integrate to get directions regardless of the grid?
     
  25. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    No, grids does not integrate each other in your example. You should set specific grid to find path. Maybe you can change pathfinding grid when your AI be on the border of the grid.
     
  26. krkim_unity

    krkim_unity

    Joined:
    Mar 30, 2018
    Posts:
    5
    ok thank you for your reply
     
  27. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    [07.31.2019] SAP2D 2019.1.3b Update:
    - Added Grid Editor Window (updated manual ostacle editing mode)
    - Added Custom dark and light GUI skins
    - Added Hotkeys for tools and brush size parameter
    - Added Context Menu
    - Added code optimizations
    - Removed SAP2D Helper script
    - Updated SAP2D About Winodow
    - Updated Documentation

    - Bug fixes

    Grid Editor Window (Light & Dark)
    s2.png s1.png
     
    Last edited: Jul 31, 2019
  28. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Quick question.

    How do you make sure that for side platformer game, the grounded agent stay on the ground not flying across the air? How do you mark ladder as walkable?
     
  29. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    SAP2D supports manually editing. I just drew unwalkable areas, everywhere on grid, without using colliders. I made walkable tile lines above platforms and ladders.
    screenshot.gif
     
    Last edited: Aug 17, 2019
  30. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Lol.. manually.. I see.. so no voodoo magic here..
     
  31. lLcrowe

    lLcrowe

    Joined:
    Sep 12, 2017
    Posts:
    7
    qa.PNG
    How can I change that grid position? it use MoveObject
     
  32. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Use SAP_GridSource.WorldPosition in code
    or
    SAP2DManager.singleton.GetGrid(0).GridPosition
     
    lLcrowe likes this.
  33. lLcrowe

    lLcrowe

    Joined:
    Sep 12, 2017
    Posts:
    7
    hm... interesting what`s happen this.
    Honeycam 2019-08-29 03-12-08.gif
     
  34. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Tile positions do not updated automatically after grid postion changed, it helps to optimize your game. Use the UpdateTilesPositions method (in code: SAP2DManager.singleton.GetGrid (0) .UpdateTilesPositions ()) to update tile positions manually, but remember that this method may decrease performace, if you have large grid.
     
    Last edited: Aug 30, 2019
  35. demeggy

    demeggy

    Joined:
    Sep 28, 2014
    Posts:
    7
  36. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    SAP2D Manager was renamed to SAP2D Pathfinder
     
  37. demeggy

    demeggy

    Joined:
    Sep 28, 2014
    Posts:
    7
    Thats grand thanks. Appreciate the quick reply.

    My top-down level gen is built where I instantiate randomises layouts within the level; now I believe that I can only have 1 instantiated version of the SAP2D object at any one time? Is it possible for me to utilise the grid mapping across multiple prefabs, but only have the controller instantiated once?
     
  38. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Yes, you should use one SAP2D Pathfinder on the scene. You can add or delete grids in SAP2D Pathfinder if you want to use more than one pathfinding grid.
     
    demeggy likes this.
  39. demeggy

    demeggy

    Joined:
    Sep 28, 2014
    Posts:
    7
    Ah perfect, so I can have multiple grids per layout object? Vunderba! I've been trying to develop an A* class for weeks now for my bloody enemies, and stumbled across this brilliant tool.

    EDIT: Sadly, I think it's erroring with Unity 2019.2.15f - When I add the Pathfinder script to my gameobject, it errors when trying to create the component UI in the Inspector.
     
    Last edited: Dec 6, 2019
  40. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Yes, You can. I usually use few grids to create something like a pathfinding layers. For example water units can move on the water tiles, but can't on the floor tiles.

    [EDIT 12.09.2019] Fixed in SAP2D 1.1.1
     
    Last edited: Dec 9, 2019
  41. Alex787

    Alex787

    Joined:
    Dec 1, 2019
    Posts:
    8
    Hi,
    How to prevent diagonal pathfinding? (For WASD turn-based movement)
     
  42. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    Hello, you should modified GetNeighborTiles() method in SAP_GridSource script.
     

    Attached Files:

    • scr2.jpg
      scr2.jpg
      File size:
      95.4 KB
      Views:
      426
  43. notSCOPY

    notSCOPY

    Joined:
    Dec 21, 2019
    Posts:
    3
    Can use this like a gps im my game?
     
  44. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    GPS Demo included.
     
  45. notSCOPY

    notSCOPY

    Joined:
    Dec 21, 2019
    Posts:
    3
    Thanks
     
  46. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    Hey, thanks for this great asset!

    I was wondering if there is a way to keep the agents full collider in mind when going around a obstacle ?

    EDIT:

    i tweaked the script SAP_GridSource.cs a bit

    i changed the line:
    Code (CSharp):
    1. Collider2D[] colls = Physics2D.OverlapCircleAll(tile.WorldPosition, tileDiameter /4, ObstaclesLayer);
    into:

    Code (CSharp):
    1. Collider2D[] colls = Physics2D.OverlapCircleAll(tile.WorldPosition, tileDiameter * 2, ObstaclesLayer);
    Now it's working perfect for me
     
    Last edited: Jan 16, 2020
  47. Jumeuan

    Jumeuan

    Joined:
    Mar 14, 2017
    Posts:
    39
    I saw you change price to Free, so will you stop support this package?
     
  48. MiSchneider

    MiSchneider

    Joined:
    Oct 28, 2017
    Posts:
    39
    I planning to release several versions to make project more usability. I want to take users feedback and I decided to share this assets at free license.
     
  49. Jumeuan

    Jumeuan

    Joined:
    Mar 14, 2017
    Posts:
    39
    Thank you so much, your A* is best and up to date 2d Grid pathfinding on the store at this moment! Really appreciate!
     
  50. Nelaha

    Nelaha

    Joined:
    Apr 3, 2020
    Posts:
    3
    Hello. I want to use your system in 3D map (flat). As im understand this is possible by translating 3D objects position to Local 2D object with SAP2D grid and calculate pathes internal in it?