Path

All things HTML5 or text based engines, or really any web based engines.
Post Reply
alex_king92
Posts: 12
Joined: Fri Aug 30, 2013 9:21 am

Path

Post by alex_king92 »

I have two questions:
1) Can I controll the speed of my entity?
2) The second question is more complex to explain. Imagin I have a "wall" of occupied tiles: (0,0)(1,0)(2,0)(3,1)(4,1)(5,1), if my entity is in (2,1) it easily can path in (3,0) with an unique movement. Is it possible to prevent this kind of movement between two diagonally neighboring tiles and say the entity to go around?
robaldred
Posts: 64
Joined: Tue Aug 27, 2013 5:54 pm

Re: Path

Post by robaldred »

HI Alex,
Thanks for your questions.
If I'm following correctly both are easy to alter.

1. Pathing speed, this is set on individual entities by setting the speed to a scalar, the higher the number the faster the entity will traverse a path.
eg:

Code: Select all

self.player.path.speed(.5) # the default is .1
self.player.path.start()
2. Allowed pathing directions.
This is configured by changing some of the arguments passed to the pathfinder aStar method.
There are two arguments which control the pathing directions allowed.
allowSquare and allowDiagonal. For what you have described you need to disable diagonals.

Have a look at the function definition in IgePathFinder.js

Code: Select all

aStar: function (tileMap, startPoint, endPoint, comparisonCallback, allowSquare, allowDiagonal, allowInvalidDestination) 
You need to set the 6th argument to false
eg:

Code: Select all

self.pathFinder.aStar(self.tileMap1, new IgePoint(0, 0, 0), new IgePoint(2, 0, 0), function (tileData, tileX, tileY) {
    // If the map tile data is set to 1, don't allow a path along it
    return tileData !== 1;
}, true, false, false);
If I've miss understood the pathing directions want, could you post a screenshot of the behaviour you'd like.

Hope that helps.
alex_king92
Posts: 12
Joined: Fri Aug 30, 2013 9:21 am

Re: Path

Post by alex_king92 »

Thanks, but have already read about aStar. I have not to disable diagonals, but avoid the entity comes between 2 other entities diagonally adjacent.
If there are two obstructions in (0,0) and (1,1), for going from (0,1) to (1,0) I want go go around respectively in (1,2), (2,1) and finally in (1,0).
robaldred
Posts: 64
Joined: Tue Aug 27, 2013 5:54 pm

Re: Path

Post by robaldred »

OK, the allow diagonals is not selective I'm afraid so its all or nothing. What you'll need to do is do the work in the comparison callback method argument 4. Determine if any adjacent tiles are occupied and return false from the callback if the adjacent tile is diagnoal to the one youre checking, thus not allowing pathing to that tile.
Post Reply

Return to “HTML5/Web Engines”