C2: pathfinding using elevators

0 favourites
  • 3 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm struggling with the implementation of a pathing system for agents who exist in a 2d building, where floors are only accessible via elevators which transport agents between floors.

    youtu.be/muiP9EZ2Cek Here is a YouTube clip to better illustrate what I mean by this.

    During the course of a play, floors and elevators may be built (and shafts expanded up and down), so the paths must be updated. In the image below, an agent on the 1st floor wishes to go 5th floor but there is no direct path. It must find a path using multiple elevators.

    Image: imgur.com/a/N9ef7Tc

    My approach thus far is to equip each agent with a stack which determines their actions via an Finite State Machine (states: idle, move, and performAction), the elevator cars also have a stack which receives movements based on agent needs, but it the whole thing lacks central planning.

    My question is how would others approach this problem? Some more savvy friends have suggested that it is a graph problem, but I'm not sure on how to technically implement something like that into Construct 2. As in how to implement a shortest path algorithm into an array containing the connected floors. Any insights would be helpful and greatly appreciated

    Edit: Realising now there is a C2 'How do I?.."

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My initial approach to this wouldn't be to plan a route using pathfinding behaviour, although I understand the agent's general movement from place to place could be pathfinding. I would do it by using the floor I am on to locate an elevator that goes to the floor I want, and if one isn't found then to the closest floor I want. Using your image as an example, this is what my approach would be :

    Elevators are objects that have variable attached to determine what floors they go to, it could be a set of booleans, floor1=true, floor2=true etc or simply a variable for the highest floor it goes to i.e. floorMax=5 it goes to 5th floor. I will use the first example for now as the second could pose problems for going in reverse, or I guess you could add a floorMin var.

    Anyway, so I am on floor 1, I look for an elevator that is floor1=true as a priority (it goes to floor 1), and also goes to floor 5 destination (floor5=true). In your image that elevator does not exist, so it then looks for the next floors down. I need an elevator that is floor1=true and floor4=true, not found. Floor1=true and floor3=true. Ok i found it, it's the elevator on the left.

    Then I get to floor 3, I look for an elevator that is floor3=true and also floor5=true. Yes that exists it's the elevator on the right, I path to this elevator and take it to 5th floor.

  • I like your approach to handling the elevators by searching for the best option first (ie, an agent chooses the elevator which travels to both his current loc, and destination) Then the second choice if an elevator which travels nearest to the location and exiting.

    I would like to know how one might actually implement a Depth First Search algorithm in Construct 2?

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