Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

PlatformerPathfinding2D (Open-source, basically alpha)

Discussion in 'Works In Progress - Archive' started by Candescence, Oct 9, 2015.

  1. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    PlatformerPathfinding2D

    Edit: Just a note, any transition away from the open-source state state for this asset is unlikely at best. On reflection, any further improvements to the code would need to be really good to be worth money, IMO, and if there's enough people contributing to it, I'd just keep it open-source. Better programmers could easily make better solutions that would actually be worth money. If the change does happen, it'll probably occur after a considerable amount of thought, feedback, and will probably just end up being a 'pro' version like the A* project. Again, unlikely to happen.

    A currently open-sourced platformer pathfinding system using a basic A* implementation, written for my own game project (which will get its own thread eventually). May become a paid asset eventually, but its currently buggy state, it's not nearly worth any real asking price.

    Since the amount of actual platformer pathfinding solutions that are available and readily usable are nearly nearly nil (I know someone is making their own implementation for the asset store, but I don't know when it's gonna be published), I had decided to try and implement a solution myself, based off princples from an article from Yoann Pignole on 2D platformer pathfinding and Sebastian Lague's wonderful A* tutorials. Pathfinding agent requires Prime31's CharacterController2D asset to work. However, since I'm running into bugs with the implementation (so close yet so far!), I felt perhaps open-sourcing this thing would be good for myself and the community, mainly to help make this properly functional and to give the community more material on this specific type of pathfinding.

    In short, I'm not so subtly looking for help on making this thing work properly and a lot better, but because I believe in giving back to the community, everyone benefits, not just myself. Platformer pathfinding is a sorely neglected, and I hope to try and help change that, despite my relatively crappy programming.

    Github Respository

    Demo Project Download (includes an editor interface and an example grid and tileset, uses Unity 5.2, press 'P' on the keyboard to place a path destination)




    Obviously, STILL MAJOR ISSUES PRESENT. THE BASIC FUNCTIONALITY STILL NEEDS SOME FIXES. It's not ready for general use yet.

    Why?

    2D platformers aren't known for complex AI, or AI that requires proper navigation of their environment. However, there are exceptions to these, and I feel that there simply isn't any pathfinding solutions that are remotely suited to the unique requirements of platforming games. Thus, designers have to implement their own solutions, or compromise on what their NPCs can do. For such a popular genre, the fact that AI pathfinding for platformers is so neglected by asset devs is puzzling.

    Other programmers could probably implement much better implementations in their sleep, but you gotta start somewhere.

    Structure and Features

    The pathfinding functionality uses a ScriptableObject-based saving system (along with a large dose of serialization). This allows the pathfinding grid to not only be editable in-editor in both edit and play modes, but also re-usable across multiple scenes if required. The grid, upon generation, performs automatic assignment of nodes of different types, and the grid can automatically generate links between those nodes.

    However, due to the way the grid is structured, it is heavily unsuited for dynamic generation of pathfinding nodes. This could be worked around in time, but at the moment, it's best used for environments that are static in nature.

    On the plus side, however, this allows more fine-grained control for the designer, especially assigning links that the generation scripts overlook.

    The pathfinding itself is fairly basic, and doesn't have a complex heuristic. An attempt to implement a heap went awry due to a bug in the heap that couldn't be properly identified.

    Best Practices

    Currently, the recommended size of grid spaces should be about half the size of the tiles in your grid, or the average environmental object if you're not using tilesets, but the grid is designed and tested for use with tilesets, currently. Nodes should have a radius of half the grid space. The smaller size ensures increased pathfinding accuracy for certain link types and allows slope nodes to be closer together to prevent inaccuracies during generation.

    It's best to avoid using the jump link generator, as it will take time, and will likely produce an excessive number of redundant links, currently.

    Current Issues

    The pathfinding often has issues with some nodes' link lists.
    The jump link generation is still somewhat inaccurate.
    The AI agent has problems with jump nodes.
    The AI agent has indexing problems when reaching the end node.

    The To-Do List

    Fix the major bugs preventing basic functionality
    Improve the editor interface and functionality
    Implement dynamic links (for things such as locked doors and other obstacles)
    Implement wall nodes
    Implement wall-scaling nodes (for wall-climbing/jumping and ledge climbing)
     
    Last edited: Oct 13, 2015
    mgear, Kellyrayj and manpower13 like this.
  2. Code to Reality Studios

    Code to Reality Studios

    Joined:
    Aug 25, 2015
    Posts:
    64
    Hey, I found a problem in your project and I cannot even run the project in Game view. Screenshot (55).png
     
  3. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    That's because you're not using Unity 5.2 (hence why I noted what version the project was using). The demo project uses specific UI features such as the new in-built dropdown menu and creating scriptableobjects from the create assets menus. You can just comment out the [CreateAssetMenu] bit, though, but the editor interface script would need a bit of reworking to work with earlier versions of Unity.
     
  4. Code to Reality Studios

    Code to Reality Studios

    Joined:
    Aug 25, 2015
    Posts:
    64
    I am using Unity 5.2.1f1
     
  5. Candescence

    Candescence

    Joined:
    Aug 26, 2014
    Posts:
    107
    Wait, seriously? That's... Interesting. I just tried testing with that version, and there's no problems. Hell, the error descriptions really make no sense in that case, hence why I presumed you had an earlier version. That is very strange.
     
  6. Code to Reality Studios

    Code to Reality Studios

    Joined:
    Aug 25, 2015
    Posts:
    64
  7. Aldwin

    Aldwin

    Joined:
    Feb 18, 2013
    Posts:
    12
    Hi Candescence,

    I'm glad my article helped you in your project :) !

    I was thinking about making a pathfinding solution for the asset store too but it means a lot of works and time (especially because the solution is dependant on how you deal with move/jumps, so how your "controller" works)...
    I hope you will succeed in your project and can't wait to see your solution.

    Yoann P.