I'm looking for a way to rotate a note 360 degrees around its z-axis. The node holding the camera moves negatively along the z-axis and is not allowed to change its y & z.
I've already tried a CABasicAnimation
, but without success.
Can anyone point me to a solution?
How about rotating it by less than 360°? Since your title says "infinitely" it should work just fine, and repeating the animation over and over will justend up being 360° and more.
Else, you can look at Apple's default SceneKit project, 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];
To rotate an object forever along z-axis.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With