# Slick Forums

Discuss the Slick 2D Library
 It is currently Sun Jan 26, 2020 8:22 pm

 All times are UTC

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: [BUG] AStar is not finding the shortest Path at allPosted: Thu Aug 02, 2012 8:07 am

Joined: Sat Jul 14, 2012 2:35 am
Posts: 19
Hey,

i was wondering why movement via astar pathfinding of the slick library was so unexpected. while avoiding an obstacle, the mover object was always moving towards the obstacle directly before travelling around.

in the implementation of the astar, it calculates the "distance" just by the cost of the given TileBasedMap. As suggested, the map could return 1 for each tile. But doing this, the cost for travelling diagonal is equal to the cost for travelling horizontal or vertical. the problem is, u cant use another value for getCost in the TileBasedMap since u dont know, from which tile u came from outside the algorithm.

Quote:
// the cost to get to this node is cost the current plus the movement
// cost to reach this node. Note that the heursitic value is only used
// in the sorted open list
float nextStepCost = current.cost + getMovementCost(mover, current.x, current.y, xp, yp);

a quick solution to this bug could be to multiply the cost by square root of 2 for diagonal movement.

greetz Ben

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ General    Games / Demos    Help / Discussion    Community Projects    Game Ideas/Design    Slick Competition 2011    Android Slick - LWJGL 2D Game Library    Announcements    Bug Reports / RFE    Extensions    Contribution depot Related Libraries and Tools    Phys2D    Tiled    TWL    Fizzy    Artemis Archive    Resolved Bugs/RFE    Useful Posts