Hello, I'm looking for a way to do simple pathfinding in c#. I have 2 rooms (a and b) with a door separating them. They can change shape at any time. The rooms are made of 1x1x1 cubes and one room (room b) has a table. While in room a I want to see if a path exists to room B's table. Of course if the door is closed and there are no breaches that opens room a to b, then it would come back as false. Could somebody point me in the right direction for pathfinding?
Check out Unity's nav mesh. There's an official tutorial here: https://unity3d.com/learn/tutorials...uction-and-navigation-overview?playlist=17105 Once you're familiar with it, you can check if a valid path exists between an agent and a target position like so: Code (CSharp): navMeshAgent.CalculatePath(targetPosition, navMeshPath); if (navMeshPath.status == NavMeshPathStatus.PathComplete) { // There is a valid path to the target positon. }
Thanks for the reply! So it sounds like navmesh would work for instance where rings are built in runtime by players? You don't have to create predefined paths?
One thing I should have asked first, are the cubes all side-by-side (dungeon keeper style)? Or are they also stacked on top of each other (minecraft style)? How many cubes are in each room exactly? No you don't need to make predefined paths. You can build nav meshes at runtime: https://unity3d.com/learn/tutorials/topics/navigation/baking-navmesh-runtime One approach would be to have a single nav mesh surface for the scene, and use obstacle carving to allow the cubes to modify the nav mesh at runtime: https://docs.unity3d.com/Manual/class-NavMeshObstacle.html
Ah ok, I've never done any minecraft/voxel style pathfinding I'm afraid. Perhaps someone else with experience in his area can weigh in?