How do I do Custom Pathfinder for Hex Maps

Get help using Construct 2

Post » Wed Aug 19, 2015 12:19 am

I'm thinking in make a game using hex maps, and after researching a bit found the support for Hex maps on Tiled.

Now I'm whiling to learn how to make this custom pathfinder system to use with the map: http://forum.mapeditor.org/t/support-fo ... s-added/47


It will have terrains costing more to move over, also, it will be jagged like this:

Image Image

So, anyone already did a system like this? and can share?

Thank you =]
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Wed Aug 19, 2015 12:37 am

Telles0808;

Rex Rainbow has an addon that does hex maps with pathfind. Not sure its exactly what you want, but take a look.

yours
Winkr7
B
34
S
8
G
3
Posts: 169
Reputation: 3,305

Post » Wed Aug 19, 2015 1:16 am

It's very nice to know, but I'm looking for the logic behind it, because using plugins will take my control over it.

Cheers!
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Wed Aug 19, 2015 4:33 am

@TELLES0808
well, kinda depends on how your game will work, are you building a two (or more) player game and want to show/highlight possible moves, or suggest the best possible move? give a hint? Or have a player play against the computer and build an AI that will be able to play the game by itself?

the logic would go something like:
specify a start block (and possibly a target block) - then if you are rolling dice, calculate all possible moves and the benefit of each move, sort them and pick the best move. Or if it is just a matter of deciding how far you can move for a specific cost, or how far you can move without making units vulnerable, then factor that into the cost/benefit of each possible move, collect the results in an array as they are calculated, sort and pick the move with the best result.

A human can glance at a board like that and rule out most of the inefficient moves instantly. A computer needs to brute force calculate every move to know what to do.
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Wed Aug 19, 2015 4:55 pm

Good point.

The game will be about Pirates and Corsairs.

The board will have ocean, with dangerous environments, also, when the wind is counter the player path, will cost more to move.

My main problem was not the human part itself, but about the logic to start making an AI good enough to chase, run away, hide itself, and take advantage routes while engaged in battle.
Last edited by TELLES0808 on Wed Aug 19, 2015 9:39 pm, edited 1 time in total.
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Wed Aug 19, 2015 7:25 pm

Its pretty much the same as isometric:
http://clintbellanger.net/articles/isometric_math/
Just think of the hexagons as iso cubes.
The offset should be equal in size.
Image ImageImage
B
170
S
50
G
178
Posts: 8,378
Reputation: 112,925

Post » Wed Aug 19, 2015 7:51 pm

Any reason for using a corner of the hexagons instead of their centers?

If done manually with events you'll use this for finding the path:
https://en.wikipedia.org/wiki/A*_search_algorithm
The difference between a hex grid and a rectangular grid is just how the neighboring grids are found. For simplicity collision detection can be used.

Here's an example:
https://www.dropbox.com/s/dwg8owxstf76g ... .capx?dl=1
/examples29/astar_hex.capx
In it it defines a function "astar", which you call with two iids: a start and and end node. After the function the start node's node.next will be the uid of the next node in the path. This can then be repeatedly followed to the end node. For smooth motion you'll have to use the moveto behavior or devise your own method.

Event #9 is where you control the cost to move to a node. Right now it uses the distance times the average of the node costs, but there's no reason you couldn't tweak it to be based on other factors.
Last edited by R0J0hound on Mon May 22, 2017 3:47 pm, edited 1 time in total.
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267

Post » Wed Aug 19, 2015 9:36 pm

Thank you @newt, I think these logics are pretty nice.
The author is very similar to my brother in appearance, lol.


@R0J0hound, Thank you for the sample, really appreciated! The sample CAPX is perfect!

The images above are using the corner to show the sample because they are from the Tiled site, this is just a random image.

The results of studies will determine if the game will be turn based, timed in lots or real time. I'm worried about the usage of CPU when dealing with 4 ships at the same time, for example.

Image
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Thu Aug 20, 2015 1:00 am

@R0J0hound - wow, that is an awesome capx example!

@TELLES0808 - CPU usage is actually quite low the way it is now (not many tiles, and it randomly chooses a goal rather than trying to find an optimum goal based other game factors). My iPhone ran it for over an hour (at 60 fps) without getting warm - and usually just about any game makes it get warm pretty fast. On my PC, cpu utilization was around 10% (after I made it wait for me choose a move it dropped to 5%.) So, I think it should scale to bigger maps with more pieces nicely.

while my phone was happily running it I was playing with the capx on my computer - I made it wait for you to click on a tile to move to, and had it display how many steps that was, and what the total cost would be. I also added a tile that cost 10 to see how it handled more complex terrain configurations. (it handled it extremely well)

That was way more fun than what I should have been working on! : )
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Thu Aug 20, 2015 2:13 am

Hi @AllanR, I noticed, thank you!

Here is a sample test of the very first alpha test of the game engine.

Don't expect too much, but thanks to R0J0, it's already working as expected.

In the next months I'll work in the AI and game aspects, to make more sprites later.

https://www.scirra.com/arcade/other-gam ... -test-1841
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Next

Return to How do I....?

Who is online

Users browsing this forum: GrogIsGood, kainrazial and 4 guests