将SCNAction应用于SceneKit中具有约束的节点 [英] Apply SCNAction to a node with constraints in SceneKit
问题描述
我有一个具有约束的节点;更具体地说,它具有SCNLookAtConstraint:
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]
但是当我想要将节点移动到其他坐标,只是不移动。我没有收到任何错误,什么都没有发生。我进行了一些测试,如果删除约束,一切正常,节点移动没有问题。所以我该怎么做?对于我的问题,有什么解决方案吗?还是我应该寻找另一种方法,使其与我的约束等效,但又与SCNAction兼容?
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?
操作代码:
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)
推荐答案
与原始海报相同。
我用MNAUGES建议解决了这个问题。
Same issue as the original poster. I solved it with MNAUGES suggestion.
LookAt约束打破/防止了SCNAction在视图中发生。有趣的是,根据控制台,摄像头节点一直在移动,只是没有在视图中更新。我还可以通过将cameraNode.position = newPosition更改为视图来移动摄影机节点,但是没有很好的动画过渡。
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.
将cameraNode关联到emptyNode。将lookAt约束分配给cameraNode,并将moveTo SCNAction分配给emptyNode。
Parent your cameraNode to an emptyNode. Assign the lookAt constraint to the cameraNode and the moveTo SCNAction to the emptyNode.
这篇关于将SCNAction应用于SceneKit中具有约束的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!