I am using SceneKit and have an app with multiple SCNNodes and when the user taps one, it will follow their finger (using a UILongPressGestureRecognizer). In the state began and changed, I am using the following line of code to change the node's position:
_currentlyMoving?.position = SCNVector3Make(worldPoint.x, worldPoint.y, worldPoint.z)
In this line, _currentlyMoving
is the SCNNode, and worldPoint the position of my finger.
This is moving the node to the correct position; however, it also appears to be changing the rotation of the node to (0,0,0) (The node is always at its starting rotation.)
Is there any way to change the position of an SCNNode without affecting the rotation?
Also, I have tried the following but it did not work either (the same thing happened):
_currentlyMoving?.transform.m41 = worldPoint.x
_currentlyMoving?.transform.m42 = worldPoint.y
_currentlyMoving?.transform.m43 = worldPoint.z
The only other thing that I am doing with the node is the following three lines to stop it from moving while picked up:
_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)