Search Unity

Best methoud for enemy pathfinding?

Discussion in '2D' started by MCrafterzz, Jun 22, 2017.

  1. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Hello, I'm creating a 2d top-down rpg and want to find a good way of making the enemies take the shortest path towards the player without getting stuck behind walls. I have seen the a* algorithment (
    ) which seems to work good, I don't know if it's good for my project tho as it will have a quite big world and therfor needs to loop through a lot of objects. Just ask if you need anymore infomation or if I have done something wrong as this is my first post in the 2d section. Thanks
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    I would think that the most Unity-integrated way would be to use NavMesh and NavMeshAgents. I'm not sure if it supports 2D colliders and orientations other than the XZ plane, but there are ways to work around that.

     
  3. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Thanks, I still seems to only work on the xz plane, is there a workaround for that as I can't change my whole game? Also is this problem planned to be fixed?
     
    Last edited: Jun 23, 2017
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
  5. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
  6. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    From the 5.6 release highlights:
    Looks like you need to use the NavMeshSurface component on your surfaces.
     
  7. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    When clicking add component and serching on nav only navmeshagent and navmeshobsticle comes up
     
  8. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    From the documentation:
    Apparently it's not built-in, it's an additional download you'll have to import.
     
  9. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Ok, I will proberly upload my game to github eventuary and then I would need to remove those files right?
     
  10. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    I don't think so, since it's open source it shouldn't be an issue.
     
  11. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Ok thanks