ios - Apply a current running SCNAction to another SCNNode -
i 2 scnnodes , b in 3d world. moved user, while b has action makes move left right. action on b:
let movedirection: float = position.x > 0.0 ? -1.0 : 1.0 let movedistance = leveldata.gamelevelwidth() let moveaction = scnaction.moveby(scnvector3(x: movedistance * movedirection, y: 0.0, z: 0.0), duration: 10.0) let action = scnaction.runblock { node -> void in } carnode.runaction(scnaction.sequence([moveaction, action]))
a , b can collide, , if touches b, has start moving b if 1 single object, until user uses commands move a. collision detected in method
func physicsworld(world: scnphysicsworld, didbegincontact contact: scnphysicscontact)
but have no idea approach should take make move b. thinking apply copy of action new positions, or if possible, apply executing action node a. thought of making a child of b , moving root node, doesn't seem work.
the solution accessing current running scnanimations on node involved in collision code:
let action: scnaction = contact.nodeb.actionforkey("movementaction")! contact.nodea.runaction(action)
once have reference current action, can run on other node, , mirrored exactly.
note: remember specify key action when create it, otherwise method won't work.
Comments
Post a Comment