Moving SCNNode relative to root root

Im learning SceneKit by writing a game in which you fly through an asteroid field while dodging objects. I initially did this by moving / rotating the camera, but I realized that at some point Id ends out of the coordinate space and it is probably better to move all the objects to the camera (and delete them when Ive "passed" them).

But I can’t make them move. My source code, which moved the camera, looked like this:

[cameraNode setTransform:CATransform3DTranslate(cameraNode.transform, 0.f, 0.f, -2.f)];

I thought I could do something similar with every node asteroid:

[asteroidNode setTransform:CATransform3DTranslate(cameraNode.transform, 0.f, 0.f, 2.f)];

but they do not move. If I add basic animation:

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.z"];
anim.byValue = @10;
anim.duration = 1.0;
[asteroidNode addAnimation:anim forKey:@"move forward"];

asteroids move, but predictably return to their original location when this is done.

, -, . ?

,

+4
1

Node , , , , "cameraNode" pointOfView (, scnView.pointOfView == cameraNode).

, "node.transform" ( "cameraNode.transform" ). :

node.position = SCNVector3Make (node.position.x, node.position.y, node.position.z + 2.0);

, , .

+2

Source: https://habr.com/ru/post/1568495/


All Articles