Moving platforms and elevator support is something that has been lacking a bit in the A* Pathfinding Project up until now. So I started thinking about it during the weekend, and figured that it shouldn’t be too hard to implement, so I did that 😀
What I ended up with was an implementation using one-way links. That is, if you have an elevator which only goes up, I would create one node at the bottom of it, and one at the top, and then add a link between them which only goes in one direction: from bottom to top.
I created a new graph type named LinkGraph, the idea is that it should always be present as the first graph in the scene. And a few scripts which enables you to create new nodes and connections using gameObjects which you place in the scene. It works similar to a list graph, but the nodes are not connected automatically, you have scripts which specify a connection from one point to another point, nodes will be created at both endpoints and automatically (currently not so sophisticated, might add more features there) connects them to nearby nodes in other graphs.
Further, I have an elevator/moving platform script which checks a trigger, if the AI stands on the platform for a specified length of time, it will lock the AI so it will not be able to move during transport to the target location, it will then move, and release the ai to move freely when it has reached it’s target location.
This simple technique works unexpectedly well in my tests.
Ways to improve it would probably be to tag the elevator nodes with certain tags which tell the AI to stop at the first one and then wait for it to move to the next instead of trying to walk towards it. That would free the elevator script from having to lock the AI from moving. It would be better in that the current system can fail if the AI walks too fast.
Here’s a video of what it looks like at the moment. Oh, and also, I have written a new AI script which has much better movement behavior than the previous AIFollow script, the one in the video is the new script, a bit modified to be able to animate the legs of the robot properly and to create a particle effect when it reaches the end of the path.