1

I have noticed that the centerOnNode: method as shown,

- (void)centerOnNode:(SKNode *)node {

    cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent];
    node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y);

}

greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left and slightly down:

enter image description here enter image description here

I drew a light blue box to estimate the physics body that it seems the paths are referencing instead of the updated frame. The lines and circles that you see represent 2 methods I am using for pathfinding.

  • The line with the dots are just ray tests that I am doing to see if a ray along the green line intersects the square physics body.
  • The single point you see at the top corner is from using GameplayKit to construct a path that avoids the black square as an obstacle.

I am struggling to figure out how to avoid the camera repositioning from effecting the positioning of the children in the scene.

FYI: I have tested the pathfinding with moving the character but NOT the camera and it works perfectly (shown below)

enter image description here

Clearly the camera offset is the issue. If anyone can tell me what to do to keep the camera movement and the precision of the pathfinding I would greatly appreciate it.

Will Von Ullrich
  • 2,129
  • 2
  • 15
  • 42
  • Did you try enabling the hit boxes to see if your physics bodies are correct? – Knight0fDragon Feb 29 '16 at 18:52
  • yea i did. they are right. I did find a work around tho - i just kept track of the camera offset and added that to the points i evaluate and it works....but only on the simulator for the `GameplayKit` method (my pathfinder works fine on both). This is yet another case where the simulator behaves quite differently than my device..very annoying. – Will Von Ullrich Feb 29 '16 at 18:55
  • well it is only a simulator, it is not an emulator, so % of error is greater lol – Knight0fDragon Feb 29 '16 at 20:36
  • i cant even get the GameplayKit methods to run on the device but on the simulator then do fine. hate the simulator.. lol – Will Von Ullrich Feb 29 '16 at 20:38
  • haven't touched gameplaykit yet so I couldn't tell you what is going on with it – Knight0fDragon Feb 29 '16 at 20:42
  • 1
    Don't move the scene to simulate a camera, especially when physics bodies are involved. If you require GameplayKit, your minimum OS also supports `SKCameraNode`. Use that instead. – rickster Mar 11 '16 at 03:22

0 Answers0