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];
[[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)]
is an instant transformation. using SCNAction animates the rotation.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.