I use SceneKit and have an application with several SCNNodes, and when the user selects one, he will follow their finger (using UILongPressGestureRecognizer). In the state started and changed, I use the following line of code to change the position of the node:
_currentlyMoving?.position = SCNVector3Make(worldPoint.x, worldPoint.y, worldPoint.z)
On this line _currentlyMoving is SCNNode, and worldPoint is the position of my finger.
This moves the node to the correct position; however, apparently, it also changes the rotation of the node to (0,0,0) (node ββis always at the initial rotation.)
Is there a way to reposition the SCNNode without affecting the rotation?
Also, I tried the following, but it didn't work either (the same thing happened):
_currentlyMoving?.transform.m41 = worldPoint.x _currentlyMoving?.transform.m42 = worldPoint.y _currentlyMoving?.transform.m43 = worldPoint.z
The only thing I do with node is the following three lines to stop it when moving:
_currentlyMoving?.physicsBody?.velocity = SCNVector3Make(0.0, 0.0, 0.0) _currentlyMoving?.physicsBody?.velocityFactor = SCNVector3Make(0.0, 0.0, 0.0) _currentlyMoving?.physicsBody?.angularVelocity = SCNVector4Make(0.0, 0.0, 0.0, 1.0)