我正在使用球作为我的球员的主要物理身体:
setup_Player () {
playerGeometry = SCNSphere(radius: CGFloat(radius))
playerGeometry.segmentCount = 64
player = SCNNode(geometry: playerGeometry)
player.geometry?.materials = [playerMaterial];
player.position = SCNVector3(x: 1, y: 15, z: 0.5)
let playerShape = SCNPhysicsShape(geometry: playerGeometry, options: nil)
let playerBody = SCNPhysicsBody(type: .dynamic, shape: playerShape)
player.physicsBody?.categoryBitMask = collisionRollingBall
player.physicsBody?.collisionBitMask = collsionTarget
player.physicsBody?.mass = 10
player.physicsBody = playerBody
scene.rootNode.addChildNode(player)
}
写了代码来修复我的播放器旁边的相机位置:
func setupCamera () {
//create a main camera
cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.camera?.zFar = 100;
cameraNode.position = SCNVector3Make(0, 0, 0)
cameraNode.eulerAngles = SCNVector3Make(0, 0, 0)
cameraNode.rotation = SCNVector4Make(0, 1, 0, Float(-M_PI_4*0.75))
scene.rootNode.addChildNode(cameraNode)
//add a secondary camera to the player
let frontCameraNode = SCNNode()
frontCameraNode.position = SCNVector3Make(0, 15, 0)
frontCameraNode.rotation = SCNVector4Make(1, 0, 0, Float(-M_PI_4*2.2))
frontCameraNode.camera = SCNCamera()
frontCameraNode.camera?.zFar = 100
player.addChildNode(frontCameraNode)
}
我只需将相机位置冻结在一定距离,就像在第三人的游戏中一样。
在这种情况下,相机会获取球的物理属性并随之旋转。但我需要关注球员和所有人,而不是以极快的速度旋转球......
如何修复播放器旁边的相机,而不是继承其属性?如何忽略物理体的旋转?
提前致谢。
答案 0 :(得分:0)
您可以更新相机的位置,只需将其添加到场景中,而不是添加到播放器中。你应该在renderer(_:updateAtTime:)
https://developer.apple.com/reference/scenekit/scnscenerendererdelegate/1522937-renderer
frontCamerNode.position = SCNVector3(x: player.position.x, player.position.y, player.position.z - 10)
我认为还需要做更多的工作,比如旋转相机等。但也许这会让你指向正确的方向。