user3765506 - 6 months ago 56

iOS Question

I am getting lost in how nodespace coordinates and rotation are handled in scenekit.

How do I get the direction a node is facing after rotation so I can then apply force in that direction.

I assumed that a force along the -z axis applied to the node would always move it forward relative to the node however this is not the case.

Answer

Negative z is the "facing" direction of a node only in its own coordinate space (i.e. the one its children and geometry are positioned in). When you apply a force, you're working in the coordinate space containing the node.

So, if you want to apply a force in a node's forward direction, you'll need to convert a vector like `{0,0,-1}`

from the node's space to its parent's using a method like `convertPosition:toNode:`

.