1
votes

I am experimenting with Apple's GameplayKit, SpriteKit and Swift. I am trying to wrap my head around pathfinding through tiles which are passable from only one side.

The diagram below shows two problems:

enter image description here

On the left is a simple solution, I understand how to move from the green position to the red position as all I need to do is remove the wall nodes (the black outlined squares) from the graph and compute the path.

The right hand side of the diagram is puzzling me. Say I want to have tiles which have a wall along their left hand side (as illustrated in the diagram) but I still want to be able to navigate to a tile with a wall. How do I go about telling the graph that those tiles with walls on the left-hand side of the tile are only passable if approached from the top, bottom or right side and not the left?

In response to Alessandro's comment I will explain about the structure of the code. I'm using the new TileMapNode introduced to SpriteKit in iOS 10 to represent the tile map. Each tile is a SKTileDefinition. Custom properties can be set on SKTileDefinition (for instance I could set an Int to represent if there is a wall on the top, bottom, left or right of the tile). The actual representation of the map is less important than how you path find with GameplayKit. As far as I can see, GameplayKit only allows you to remove nodes from the graph that are impassable but what I want to do I mark some nodes as passable but only from a particular direction.

This strikes me as a common problem (as lots of games don't have to sacrifice an entire tile to represent an internal wall) but I don't have the faintest idea how to go about it.

1
What is the tile? Is it a SKSpriteNode? What dimension do you want it have? Are you using a 3d part library for TileMap? How can you move your character? What is wall? After your question I have more question than you, so please post some code, some details, this question seems a TV quiz.Alessandro Ornano

1 Answers

1
votes

You have a couple options:

1) Decrease your grid size. The presence of thin walls suggests your grid size could be smaller (on the order of the smallest obstacles)

2) Use a different graph type and abandon the grid altogether. GKObstacleGraph or GKMeshGraph are well suited to a game world that has a number of arbitrary polygonal obstacles.