Reputation: 681
I have a cube that I created using Scenekit for ios. I want the cube to move from one point to another. How can I do that? I read the Apple documentation on the runAction method. But I do not know how to implement it.
Upvotes: 3
Views: 3090
Reputation: 28982
To run an action on an object, you have to create the action first. For moving an object around the scene, create an action like this:
let moveTo = SCNAction.moveTo(SCNVector3Make(1, 1, 1), duration: 1)
This will move the object you run the action on to the point 1, 1, 1
.
If you would rather move the object by some value, you can do that the following way:
let moveBy = SCNAction.moveByX(0, y: 1, z: 0, duration: 1)
Then, simply run the action on the object you want to move:
myObject.runAction(moveBy)
You can of course make this shorter and instead of creating a variable for the action, create the action right within .runAction()
, but it makes it easier to read sometimes.
Hope that helps :)
Upvotes: 10