360 ° SCNNode rotation

I am looking for a way to rotate a note 360 ​​degrees around its z axis. The camera node holding the camera moves negatively along the z axis and cannot change its y and z. I have already tried CABasicAnimation, but to no avail.

Can someone point me to a solution?

+4
source share
3 answers

How to rotate it less than 360 °? Since your title says “endlessly”, it should work very well, and repeating the animation over and over will be 360 ​​° or more.

Alternatively, you can check out the default Apple project SceneKit, which works great for me:

[cameraNode runAction:[SCNAction repeatActionForever:[SCNAction rotateByX:0 y:.5 z:0 duration:1]]];

Or, for OSX:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"rotation"];
animation.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(0, 0, 1, M_PI*2)];
animation.duration = 15;
animation.repeatCount = MAXFLOAT; //repeat forever
[YOURNODE addAnimation:animation forKey:nil];
+5
source
[[ZnodeOnly physicsBody] setVelocityFactor:SCNVector3Make(0, 0, 1)];

[[ZnodeOnly physicsBody] setAngularVelocityFactor:SCNVector3Make(0, 0, 1)];

[RotatingNode runAction:[SCNAction repeatActionForever:[SCNAction rotateByAngle:-360/(180/M_PI) aroundAxis:SCNVector3Make(0, 0, 1) duration:1]]];

[node setRotation:(x,y,z, w)] - . SCNAction .

+1

Z.

let node = SCNNode()
self.sceneView.scene.rootNode.addChildNode(node)
//creating an box object
node.geometry = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
node.geometry?.firstMaterial?.diffuse.contents = UIColor.blue
node.position = SCNVector3(0,0,0)
//adding a rotation by Z axis        
let action = SCNAction.rotateBy(x: 0, y: 0, z: CGFloat(GLKMathDegreesToRadians(360)), duration: 8)
let forever = SCNAction.repeatForever(action)
node.runAction(forever)
0

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


All Articles