Pathfinding in top view

0 favourites
  • 6 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • 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 :

    <img src="http://img12.imageshack.us/img12/7301/pathfinding.jpg" border="0" />

    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 !

  • Sylvain,

    Try searching in the Forums for "pathfinding".

    There are an abundance of pathfinding references on the forums.

  • 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.

  • 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: 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).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 ?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)