Pathfinding in top view

Get help using Construct 2

Post » Tue Sep 11, 2012 3:15 pm

In top view (8 directions controller), how can I implement pathfinding to monsters who purchase the player ?

Here is a quick drawing of the issue :



No problem for doing the case on the left (I plug monster direction on player X and Y) , but how can I do the case on the right of the picture ? The monster could avoid solid sprites or any obstacles.

Thanks for help !
B
40
S
9
G
5
Posts: 127
Reputation: 6,609

Post » Tue Sep 11, 2012 3:22 pm

Sylvain,

Try searching in the Forums for "pathfinding".

There are an abundance of pathfinding references on the forums.Wastrel2012-09-11 15:24:21
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Sep 11, 2012 3:33 pm

Searched in How do I FAQ and Tutos, and I found nothing.
Searched in the forums and I found a lot of Construct Classic pathfinding issues, but no for Construct 2. I feel sorry but I guess I missed something.Sylvain2012-09-11 15:33:23
B
40
S
9
G
5
Posts: 127
Reputation: 6,609

Post » Tue Sep 11, 2012 3:43 pm

Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Sep 11, 2012 5:33 pm

Doing it with events maybe a Real Challenge, so, be prepared, or you'll need to use plugins, which are not accepted on the Arcade (I think, last time didn't uploaded the game).

A way of doing it is avoiding to hit with the wall by doing collision masks detectors around the monster, do 4 of them, one for each cardinal.

If the monster collide with the wall and his top mask is overlapping the wall, he need to walk left or right, if he is on a corner, his left or right masks and his top or down masks are overlapping the wall, so, you can set him to walk to the opposite side, for example.

The main issue is about detecting the player and the pathway. For example, if the player is behind a wall, but the only entrance for his room is on the middle while your player is in line with the monster, and your monster detected the wall and avoided it, he will never find the entrance.

Then, now you know you'll need to make a matrix of tiles over each level, checking each slot of the matrix and making a reliable path by knowing what slot is over what type of sprite.

To make easy the detection, simple put the sprite objects of the canvas on families, like wall sprites on the the wall family.

For example, if you have a canvas with 320x240 pixel and want make a matrix over it to check the paths, make it with slots of 20x20 pixels, by simple using an invisible object. The array here will have the width of 16 tiles and height of 12 tiles.

After it, you need to make the math (magic) to check the best path (if existent) to reach the player, and when the way is blocked, the treatment this this exception.

I think the first thing becoming to my brain now is solve the matrix.

Well, it's a really long way to solve the matrix and I don't want explain all the trick of this way here.

You can learn more reading this very very beginner guide: http://www.policyalmanac.org/games/aStarTutorial.htm

Or wait til December, where I'll make a very complete pathfinder using events and share here on Scirra ^^ (First I need to learn about it like you'll need, I feel we are all beginners here).
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Wed Sep 12, 2012 8:44 am

Thanks for your answers !
I'll try the plugin in a first time, but in fact I don't like to use external plugins for Construct 2. Maybe it's silly to think that but I prefer focus myself on C2 possibilities.

TELLES0808 > Thank you for your reply :)
It's a bit complicate to use matrix, in a first time but it's very intersting. I'll try to implements "avoiding solid" to my monsters in a first time.
By the way, what do you mean by "top mask" ? an invisible sprite bigger than the monster, pinned to it to manage collision / overlapping with other solids ?
B
40
S
9
G
5
Posts: 127
Reputation: 6,609


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests