Advertisement
Guest User

GK Grid Path Finding issue

a guest
Mar 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.52 KB | None | 0 0
  1. import GameplayKit
  2.  
  3. var nodes = [GKGridGraphNode]()
  4.  
  5. let maxSize = 3
  6.  
  7. //Here I'm filling the elements of the grid
  8. for i in 0..<maxSize {
  9.   for j in 0..<maxSize {
  10.  
  11.     let node = GKGridGraphNode(gridPosition: vector_int2(Int32(i), Int32(j)))
  12.     nodes.append(node)
  13.   }
  14. }
  15.  
  16. let graph = GKGridGraph(nodes)
  17. let start = GKGridGraphNode(gridPosition: vector_int2(0,0))
  18. let end = GKGridGraphNode(gridPosition: vector_int2(2,2))
  19.  
  20. let path = graph.findPath(from: start, to: end) //It returns an empty array
  21. print(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement