0

For example I have two SCNNodes with SCNBox geometry positioned one after another increasing x position property:

SCNBox(width: 0, height: 0, length: 0.02, chamferRadius: 0)

Then I want to rotate the first one using rotation property with SCNVector4, but when rotation happens I want my second node to follow the first one and change its position according rotation of the first one.

I found this solution on the web and tried to print node's position, worldPosition and presentation.position but they are all the same value.

Can someone help me to find out how can I obtain node's position after rotation?

mkz
  • 2,302
  • 2
  • 30
  • 43
  • You want the second node to rotate around move around the first one? Like it is in an orbit? – SWAT May 22 '18 at 12:22
  • @SWAT yes, like if they were only one node – mkz May 22 '18 at 12:31
  • Did you make the second node the child of the first node? – SWAT May 22 '18 at 14:02
  • If you have same values for the position and worldPosition, then your nodes must be child nodes of the rootNode. Make the second node the child of the first node. Your second node should then rotate around the first node, when you rotate the first node. – SWAT May 22 '18 at 14:05
  • @SWAT thank you a lot, I've actually solved this issue following your advice. I have added second node as a subview to the first and then change its position `SCNVector3Zero` with `x` offset. – mkz May 30 '18 at 15:09

1 Answers1

0

The position of a node does not change when it rotates. Maybe you could look at connecting the nodes with a physics mechanism such as SCNPhysicsHingeJoint? I found this example which could be useful for your scenario:

enter image description here

http://lepetit-prince.net/ios/?p=3540

Another example:

enter image description here

http://appleengine.hatenablog.com/entry/2017/08/17/154852

Oskar
  • 3,625
  • 2
  • 29
  • 37