How would you design the pathfinding for this game scenario?

0 favourites
  • 4 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm looking for feedback on how to best implement pathfinding for my game idea.

    I've made a small illustration to make it easier for you to understand what I'm talking about:

    You're looking at this 2d building from the side. You've got multiple rooms and between the rooms there are doors that can either be locked or open and there are ladders connecting the two floors.

    Let's say we now have a character in the building. And he (let's imagine it's a guy) stands in Room 2. To move him you click on him and select where you want him to move. If you click in Room 6 he will try to find a way of getting there and then walk there. In this case he would need to move to Room 3 -> Room 4 -> Room5 -> Room 6 to get there.

    I want you to help me with ideas of how to best implement the pathfinding and routing for this kind of game mechanics. Is there any way to adapt the pathfinding behaviour so that it will work with this, or will I be better of by making my own implementation?

    It should be possible to create arrays containing information about which rooms are connected to eachother and then implement a routing algorithm for finding possible ways to get to the destination. But I really want to make it as simple (but still good of course) as possible so therefore I will be happy to recieve some feedback from other people.

  • First of all ...there are so many ways to do this...

    the fastest way would be to just add the pathfinding behaviour to your player and use that..

    making sure that you add out all of the walls etc as obstacles

    but because this may not look right..your player would in some places..take the shortest route ..which may mean 'FLYING' in places they shouldnt

    to solve this if and only if it suits your game

    you would create a maze of blocking sprites that are invisible at run time.

    making sure that your character fits between the maze walls as required with no room for "flying"

    and of course you would still have to change animations when the player reaches a ladder but this should be easy and not affect the pathfinding at all ..because its just animations not mechanics

    one other way could be to mod a platformer sprite and add pathfinding behavior to another object that the platformer 'follows'

    basically using the pathfinding object to find the path or waypoints then make the platformer follow the pathfinding objects x po

    and if and when the pathfinder moves up or down a floor level..then and only then does the platformer climb

    you would need to create a sprite with 'PATHFINDING BEHAVIOUR'

    you may as well use the built in features..there is no reason why you cant modify its usage to suit your game

    then secondly make your Player controller sprite and add a 'platformer' behaviour or custom movement ( based on your layout above you seem to require this..not 8dir)

    the movement speeds of each should be the same for each object so that they cant get away from each other

    you could even get the path finding object to spawn waypoint sprites which either drop to the floor or spawn at a fixed height depending on which floor the pathfinder object is currently on and spawn every second or so..

    which the platformer then moves to these objects waypoints

    these are just some ways...that use the built in pathfinding...

    just mod it to suit your needs

    its a pretty robust behaviour like all c2 behaviors there is alot more ways to use them than you might think

    be flexible...let your mind flow with ideas...do lots of tests/experiments..you will see so many other ways

    one of the will suit your game perfectly

    hope that helps

  • Thanks for a great and detailed answer!

    I think I'll go with the idea to have the character follow an object with the pathfinding behaviour. I think it'll be one of the best methods for this case.

    Thank you very much!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jimutt.......You are most welcome ..hope it works out

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