Run SCNActions sequence with different nodes in SceneKit

I know how to create a sequence of SCNActions in a single node, one by one, in SceneKit. But I would like to know, how can I make a sequence of SCNActions with different nodes? For example

  • Move forward node A
  • Move forward node B
  • Wait 1 second
  • Move backward node A

I found an example with SpriteKit but I can not use it.

The code of a sequence is as follows

var sequence = [SCNAction] () let force = SCNVector3(0.0, 0.0, -1.0) let move = SCNAction.move(by: force!, duration: 1.5) squence.append(move) let actions = SCNAction.sequence(squence) nodeSelected?.runAction(actions)

Accepted Reply

Make a sequence that calls functions instead of move actions. Those functions will move your various nodes. So you'll be running the sequnce on the scene instead of any specific node. Although, I guess it could be run on a node. Here's an example....


let wait:SCNAction = SCNAction.wait(duration: 3)
let runAfterWaiting:SCNAction = SCNAction.run { _ in
           
            //do whatever you want here.... if you call a function, write self in front
           
}
let seq:SCNAction = SCNAction.sequence( [wait, runAfterWaiting ] )
sceneView.scene.rootNode.runAction(seq)

Replies

Make a sequence that calls functions instead of move actions. Those functions will move your various nodes. So you'll be running the sequnce on the scene instead of any specific node. Although, I guess it could be run on a node. Here's an example....


let wait:SCNAction = SCNAction.wait(duration: 3)
let runAfterWaiting:SCNAction = SCNAction.run { _ in
           
            //do whatever you want here.... if you call a function, write self in front
           
}
let seq:SCNAction = SCNAction.sequence( [wait, runAfterWaiting ] )
sceneView.scene.rootNode.runAction(seq)

Thanks for your help 🙂