I have beens struggling with the following. In the game I am developing with Unity 5 in C#, I need to implement basic pathfinding over moving platforms (not with moving platforms). It means, I am not concerned that NPC are able to take moving platforms, I am specifically concerned that the whole pathfinding process should happen on big moving floors.

Being that the case, NavMeshes are not an option. Would anyone happen to know of any approach, or have any good tips for that? Thanks in advance for your time.

  • \$\begingroup\$ Thanks for the comment! The assets available do not handle pathfinding performer over a floor that's moving, they only do pathfiniding with moving platforms, i.e. pause the pathfinding while NPCs are taking elevators, etc. About your other suggestion, you mean creating meshes as waypoints and making them move with the platform so the NPCs will follow the path over the moving floor? \$\endgroup\$ – Andy Astro Sep 19 '15 at 10:03
  • \$\begingroup\$ That's an excellent suggestion, actually. However, I am not still sure that by doing so, the character would move with the platform as well. But I guess one could just not use a Rigidbody component (since in Unity 5 moving a static collider does not hit performance anymore) and then follow what you have said. Put these comments of yours as an answer so I can accept and upvote it \$\endgroup\$ – Andy Astro Sep 27 '15 at 19:49
  • \$\begingroup\$ Using a CharacterController or Rigidbody will move the character along with the platform. Make sure the platforms have kinetic Rigidbodies too \$\endgroup\$ – EvilTak Sep 28 '15 at 0:50
  • \$\begingroup\$ EDIT: Comments converted to answer \$\endgroup\$ – EvilTak Sep 28 '15 at 0:53
  • \$\begingroup\$ Why don't you parent the Navmesh to the moving platform? \$\endgroup\$ – Školstvo Dec 27 '15 at 11:20

You could create your own waypoint-based graph, update it every frame and perform a Breadth First Search on that, or you could maybe try looking at one of the A* projects (there are free ones) on the Asset Store.

To make the waypoint graph, Make the waypoints a child of the platform they represent, so that they move with the platform. You could set a waypoint tag on your waypoints and search for all waypoints in your player script. The waypoint should have a MonoBehaviour which contains the other waypoints it is connected to. Thus you have the nodes and edges of a graph. You can perform a simple Breadth First Search or use your implementation of Dijkstra's or A* for traversing the graph.

Then you could check the height difference between this and the next waypoint in your traversal and if it is higher than a certain amount, you won't go there (that is a platform is above the character), a bit like how navmeshes are baked. If you need more help implementing this, feel free to ask.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.