我创建了一个玩家可以在其中移动的 SceneKit 3D 迷宫世界。像跳跃这样的一些动作涉及上下移动相机,同时在几秒钟的时间内改变观察方向。在此期间,我想忽略用户的点击和滑动,这通常会导致其他类型的运动,如转身和向前移动。
我可以创建一个与跳跃持续时间相匹配的计时器并设置一个布尔值,但我希望有一种更简单的方法来检查相机的 SCNNode。
是否有一种简单的方法可以查看相机的 SCNNode 是否不再运行 SCNAction 进行跳转,以便我可以在其他点击和滑动操作之前添加此逻辑?
或者也许有一个 SCNAction 可以设置我可以在跳跃序列的开始和结束时放置的 Bool?
这是我的跳转代码:
let jumpUp: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), jumpHeight), duration: jumpTime)
let jumpAppex: SCNAction = SCNAction.wait(duration: jumpWaitTime)
let fallDown: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), cameraHeight), duration: jumpTime)
var lookDown: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(π), duration: jumpTurnTime)
let noLook: SCNAction = SCNAction.wait(duration: jumpTime*2.0)
var lookBack: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: 0, duration: jumpTurnTime)
switch playerDirection.direction
{
case .south:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
case .north:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
case .east:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
case .west:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
}
let sequenceJump = SCNAction.sequence([jumpUp, jumpAppex, fallDown])
let sequenceLook = SCNAction.sequence([lookDown, noLook, lookBack])
mazeScene.mazeCamera.runAction(sequenceJump)
mazeScene.mazeCamera.runAction(sequenceLook)
谢谢
格雷格