Apply SCNAction to a node with constraints in SceneKit

此生再无相见时 提交于 2019-12-12 01:46:57

问题


I have a node that have a constraint; to be more specific, it has an SCNLookAtConstraint :

    let constraint = SCNLookAtConstraint(target: scene.retriveNodeFromScene(cameraNodeName))
    constraint.gimbalLockEnabled = false
    self.constraints = [constraint]

But when I want to move node to other coordinates it just doesn't move. I don't receive any error, just nothing happens. I have made some tests, and if I remove constraint, everything is ok, node moves with no problem. So, what should I do? Is there any solution for my problem or should I find another way, equivalent with my constraint, but also compatible with SCNAction?

code for action:

    let timeForAction = calculateTimerForSecoundAction()
    let action = SCNAction.moveTo(calculateEndingLocation(), duration: timeForAction)
    let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_SEC * timeForAction))
    self.runAction(action)
    explodeAfterReachingFinalPosition(timeForAction)

回答1:


you could create a new intermediate node that you'll use for the action, and have your current node as a child node with the lookAt constraint.




回答2:


Same issue as the original poster. I solved it with MNAUGES suggestion.

The 'LookAt' constraint breaks/prevents the SCNActions from happening in the view. Interestingly, the camera node WAS moving - according to the console - just not updating in the view. I could also move the camera node in the view with a change to cameraNode.position = newPosition - but without the nice animated transition.

Parent your cameraNode to an emptyNode. Assign the lookAt constraint to the cameraNode and the moveTo SCNAction to the emptyNode.



来源:https://stackoverflow.com/questions/30620806/apply-scnaction-to-a-node-with-constraints-in-scenekit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!