Swift 正在调用SCNNode.runAction(Scenekit)重置节点位置
我目前有一个应用程序,它可以让Scenekit中的一个飞船节点以恒定的速度在太空中飞行。我实现了一个d-pad系统,该系统基于触摸移动旋转飞船,最终目标是用户可以在飞船穿越太空时旋转飞船,并将其移动到您指示的方向 我现在遇到的问题是,ship节点的位置在每次新触摸开始时都会重置,并且只有在完成触摸后才会向前移动 下面的代码是我的d-pad控制船舶方向的实现:Swift 正在调用SCNNode.runAction(Scenekit)重置节点位置,swift,scenekit,scnnode,scnaction,Swift,Scenekit,Scnnode,Scnaction,我目前有一个应用程序,它可以让Scenekit中的一个飞船节点以恒定的速度在太空中飞行。我实现了一个d-pad系统,该系统基于触摸移动旋转飞船,最终目标是用户可以在飞船穿越太空时旋转飞船,并将其移动到您指示的方向 我现在遇到的问题是,ship节点的位置在每次新触摸开始时都会重置,并且只有在完成触摸后才会向前移动 下面的代码是我的d-pad控制船舶方向的实现: extension GameViewController { override func touchesBegan(_
extension GameViewController {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
touch = touches.first!
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touch {
let touchLocation = touch.location(in: self.view)
if gameView.virtualDPad().contains(touchLocation) {
let middleOfCircleX = gameView.virtualDPad().origin.x + 75
let middleOfCircleY = gameView.virtualDPad().origin.y + 75
let lengthOfX = Float(touchLocation.x - middleOfCircleX)
let lengthOfY = Float(((touchLocation.y - middleOfCircleY) * (-1)))
let turnY = lengthOfX/47.746371
let turnX = lengthOfY/47.746371
let action = SCNAction.rotateTo(x: CGFloat(turnX), y: CGFloat(turnY), z: 0.0, duration: 2.0, usesShortestUnitArc: true)
shipMesh.runAction(action)
}
}
}
}
扩展GameViewController{
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
首先!
}
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
如果让触摸=触摸{
让touchLocation=touch.location(在:self.view中)
如果gameView.VirtualPad()包含(touchLocation){
让middleOfCircleX=gameView.virtualPad().origin.x+75
让middleOfCircleY=gameView.virtualPad().origin.y+75
让lengthOfX=浮动(touchLocation.x-middleOfCircleX)
设lengthOfY=Float(((touchLocation.y-middleOfCircleY)*(-1)))
让turnY=lengthOfX/47.746371
让turnX=lengthOfY/47.746371
让action=SCNAction.rotateTo(x:CGFloat(turnX),y:CGFloat(turnY),z:0.0,持续时间:2.0,使用shortestunitarc:true)
shipMesh.runAction(操作)
}
}
}
}
有人能告诉我如何让飞船在穿越太空的同时旋转吗?好的-看起来你自己已经回答了,所以我们应该关闭它
@LittleRocketMan->在我的分机上添加了第二个命令,它成功了。你是如何以恒定速度移动船的?是通过科学还是物理学?目前的动态物理学。SCNAction会更好吗?在我的扩展中添加了第二个SCNAction,它成功了。谢谢你的帮助!