Slick Forums

Discuss the Slick 2D Library
It is currently Thu Aug 16, 2018 4:45 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jun 18, 2012 8:58 pm 
Offline

Joined: Mon Jun 18, 2012 8:51 pm
Posts: 1
The below code is from my enemy movement function in my game. As you can see I have tried some debugging, and everything returns normally. FindTarget() returns the player position, I turn both of them into grid (or map if you prefer) coordinates, and then feed them into the pathfinder. But for some reason I always get a null result, and I have no clue why.

Code:
//find grid position of target
        Vector2f tarPos = FindTarget();
        int tarX = (int)tarPos.x/25;
        int tarY = (int)tarPos.y/25;
        //find my grid position
        int myX = (int)position.x / 25;
        int myY = (int)position.y / 25;
       
        System.err.print("target x: " + tarX + " target y: " + tarY + "\n");
        System.err.print("start x: " + myX + " start y: " + myY + "\n");
       
        pathFinder = new AStarPathFinder(Map.GetMap(), 100, false);
        Path path = pathFinder.findPath(null, myX, myY , tarX, tarY);
       
        if(path == null){
            System.out.print("Failure creating path\n");
        }
        else{
            int length = path.getLength();
            System.out.println("Found path of length: " + length + ".");

            for(int i = 0; i < length; i++) {
                System.out.println("Move to: " + path.getX(i) + "," + path.getY(i) + ".");
            }
           
        }


Top
 Profile  
 
PostPosted: Sat Jul 21, 2012 11:19 pm 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
try it with distance 1000 or more instead of 100.
and maybe you should use instead of null a dummy mover like this.
Code:
Mover dummy = new Mover() {};


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group