Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dynamic 2D pathfinding

Discussion in 'Scripting' started by DhiaSendi, May 16, 2018.

  1. DhiaSendi

    DhiaSendi

    Joined:
    May 16, 2018
    Posts:
    42
    Hi,my video games development skills are still in progress i want some help with pathfinding in a 2D environment
    i already tried some a* implimented algorithm but i am more interested in dynamic pthfinding,because in my game i need sometimes to create a new obstacles so the algorithm recalculate and made a new path
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    Astar can do exactly what you need: simply find the best path and follow it, and periodically, depending on how much CPU time you want to spend on it, recalculate the path. If the environment changed, you will get the new pathf.

    You can also trigger the recalculation only whenever you know something has changed, i.e., door opened/closed. It would be entirely up to you how often to check for a change.
     
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    As another option, if you are wanting a ready made solution, then you could try Navigation2D. It works quite nicely and handles dynamic path re-routing.