A better method to track distance in a tilemap with PathFinder and NO diagonal movement?

37 views
Skip to first unread message

JustGabe

unread,
Feb 27, 2016, 12:54:47 PM2/27/16
to HaxeFlixel
I have 2 issues:

1) Is there a way for a sprite to move through a tilemap with PathFinder but only with vertical and horizontal movements?

2) I want to make an AI where the enemy tracks the nearest player and moves towards it, the problem is that using "nodes.length" doesn't seem to be helpful.
In the image below, when I click the lowest red square it throws that the player to the far left is "nearest" than the player who's near center only because the nodes length is 2 and the other is 3, even though it needs to move 7 tiles versus only 6 tiles from the other player. So, what could be a better way to track distances and find the nearest player?


Dondudu

unread,
Feb 27, 2016, 7:51:01 PM2/27/16
to HaxeFlixel
1. set the diagonal policy for FlxMap.findPath. Reference this http://api.haxeflixel.com/flixel/tile/FlxTilemapDiagonalPolicy.html
2. You can iterate through the array of path points, and sum the distance difference between each successive point. This will tell you how long the path is.

JustGabe

unread,
Feb 28, 2016, 1:11:37 AM2/28/16
to HaxeFlixel
Really helpful, thank you!
Reply all
Reply to author
Forward
0 new messages