Search code examples
scenekitpath-findinggameplay-kit

Can I combine GameplayKit's pathfinding features with SceneKit?


The documentation states

GameplayKit also works well for 3D games built with the SceneKit framework

However, there seems to be no mention of using SceneKit's pathfinding features such as GKGraph with SCNNodes that exist in 3d space.

Are GameplayKit's pathfinding feature unsuitable for SceneKit games, or is there extra documentation somewhere to illustrate how to combine the two?


Solution

  • Depends on the scenario really. My current side project is a SceneKit based boat game; boats move on a 2D plane which means GameplayKit's 2D pathfinding works well.

    It's not without complications though... SpriteKit gives you some useful functions such as obstaclesFromSpriteTextures:accuracy:, to help with the generation of your pathfinding graph. There is no corresponding function in SceneKit. I've adopted the approach of rendering my scene 'top down' to an offscreen buffer, and using edge detection to trace around the 2D projection of my islands.

    For full 3D pathfinding I can't see GameplayKit being much help, well not without some hacks (eg; break 3D pathfinding down into several 2D planes).