[LIB] A* Pathfinding Algorithm

Discussion in 'Resources' started by Adamki11s, Feb 16, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    unforgiven5232

    Adamki11s
    how do you define the locations "nodes" for your entity?

    Adamki11s
    If you would please explain to me how to make a start location for a zombie and then make him walk to and end location T.T

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. unforgiven5232
    Well to do with an entity is more complicated.

    What you would probably have to do in this instance is create a pathfinder object to find a path from your start to end location. Then you would have to override the mob's pathfinding and make it was to each node subsequently in the tile array.

    Take a look in the resources section for adding custom behaviour to mobs. And take a look over at the source code I linked you to my QuestX plugin on github.
     
  3. Offline

    unforgiven5232

    alright thanks i'll try and get on that
     
  4. Offline

    pixelzee

    Is there any way of making an entity that uses this pathfinder to walk to the path smoothly, I tried it out and it was very choppy
     
  5. Offline

    nolizwe

    Hey, well I dont really know how peoples packages work but the thing will not compile i keep getting this error.
    1 error found:

    Error: File is in the wrong directory or is declared part of the wrong package. Directory name 'Downloads' does not match package name 'adamki11s'.
    and
    cannot find symbol World Location etc and package does not exist how do i intergrated it with my stuff
     
  6. Offline

    Plo124

    My code isn't functioning properly, this is my code
    Code:java
    1. public void runPathing(final Location start, final Location end, final int range, LivingEntity ent){
    2. try {
    3. AStar path = new AStar(start, end, range);
    4. ArrayList<Tile> route = path.iterate();
    5. PathingResult res = path.getPathingResult();
    6. switch(res){
    7. case SUCCESS :
    8. move(start, route, ent);
    9. break;
    10. case NO_PATH:
    11. break;
    12. }
    13. } catch (InvalidPathException e) {
    14. }
    15. for(Tile t : tiles){
    16. Location loc = t.getLocation(start);
    17. path.add(loc);
    18. mobs.add(ent);
    19.  
    20. }
    21. }


    It works fine, and Im iterating through each block to guide the sheep to the player, but once it gets to the target, it goes backwards again, and the sheep walks most of the way back, and walks to the start again.
     
  7. Offline

    ToastHelmi

    does this lib also checks if ther is a to block high way?
     
  8. Offline

    Jumla

    How does the performance of this algorithm compare to that of vanilla minecraft
     
  9. Offline

    bars96

    How to apply this pathfinding algorithm to zombies?

    Adamki11s

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  10. Offline

    Splated

    Adamki11s I been looking for something like this!
     
    Adamki11s likes this.
  11. Offline

    sebasju1234

    This is awesome, I've always wanted to implement the A* pathfinding algorithm in one of my plugins. Thank you!
     
  12. Offline

    Robin Bi

    Adamki11s Sorry that i pick up this old thread, but i am currently trying to work with your lib.
    So i want to let some zombies walk through a cliff. This is my current code:
    Code:java
    1. public class WalkingEnemies {
    2.  
    3. public void letThemWalk(Location start, Location end, int range) {
    4.  
    5. try {
    6. // Create Pathfinder
    7. AStar pathFinder = new AStar(start, end, range);
    8. // Get the list of nodes to walk to as a Tile object
    9. ArrayList<Tile> route = pathFinder.iterate();
    10. // Get Result of the path trace
    11. PathingResult res = pathFinder.getPathingResult();
    12. } catch (InvalidPathException e) {
    13. // Wird geworfen, wenn Start- oder Endblock nicht solid ist
    14. if (e.isStartNotSolid()) {
    15. System.err.println("Start block is not walkable.");
    16. }
    17. if (e.isEndNotSolid()) {
    18. System.err.println("End block is not walkable.");
    19. }
    20. }
    21. }
    22.  
    23. }


    This does not contain anything with zombies, just because i don't know how to let the entities work with your lib... While writing this i notice that it might be a silly question, but i hope someone can help me anyways :3
     
  13. Offline

    Spartan322

    Thank you for creating this (it seems much better then minecraft's built in pathfinding for mods with special requirements) I have recently converted this to be usable in minecraft forge 1.7.10 and it also now does pathfinding for flying mobs. I like to say thank you for doing this
     
  14. Offline

    lenis0012

  15. Offline

    ArthurHoeke

    This is a nice lib, got it working but how to make that a mob will acually follow this path?
     
  16. Offline

    ZP18

    This looks so cool!!!! I can't wait to try it out! When I manage to learn how to use this fully, I will make a tutorial for all the people who are having trouble with it
     
Thread Status:
Not open for further replies.

Share This Page