Reputation: 2093
I have two SCNNodes which have a geometry type set to SCNBox.
let node1 = SCNNode(geometry: SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0.0))
let node2 = SCNNode(geometry: SCNBox(width: 20.0, height: 10.0, length: 10.0, chamferRadius: 0.0))
node1.position.x = 0.0
node2.position.x = 10.0
scene.rootNode.addChildNode(node1)
scene.rootNode.addChildNode(node2)
When I look at my scene then the nodes are overlapping, however they should not, or should they? I don't manipulate camera at the same time. For now I don't have any physics field set.
When I print the following:
node1.presentationNode.position.x
node2.presentationNode.position.x
or
(node1.geometry as! SCNBox).width
(node2.geometry as! SCNBox).width
Then the values that are printed as the same as the ones that were initially set. Is the anchor point of the node by default the left down corner? The strange thing is that when I move the node in touchesBegan/touchesEnded and position it at the same position then the nodes don't overlapp. How to place nodes of the SceneKit correctly?
Upvotes: 0
Views: 2496
Reputation: 2093
Thank you for help. I found the solution. Nodes are positioned based on the anchor point which is in the middle of the node's width.
Upvotes: 1
Reputation: 2833
I believe you are getting your axis mixed up. The width of node2 is 20, but you are only moving node1 (width of 10) by 10. Try moving it by 20 (or 23 for a small gap).
Upvotes: 0