我将角色移动到场景上方,每func update(deltaTime)
更改其位置。地板物理车身代码设置:
if let floor = mapTileNode.childNode(withName: "floor", recursively: false) {
floor.physicsBody = SCNPhysicsBody.static()
floor.physicsBody?.physicsShape = SCNPhysicsShape(node: floor, options: [.type: SCNPhysicsShape.ShapeType.boundingBox])
floor.physicsBody?.collisionBitMask = BitMask.hero
floor.physicsBody?.categoryBitMask = BitMask.floor
}
每次移动角色时,我都会执行rayTest:
let ndpoint0.y = -0.1
let endpoint1.y = 0.1
let results = scene.physicsWorld.rayTestWithSegment(from: endpoint1, to: endpoint0,
options: [.collisionBitMask: BitMask.wall | BitMask.floor,
.searchMode: SCNPhysicsWorld.TestSearchMode.closest])
if let result = results.first {
let groundAltitude = result.worldCoordinates.y
print("groundAltitude", groundAltitude)
}
我希望groundAltitude
每次都是0.0。但是groundAltitude
类似于:
groundAltitude 0.041623943
groundAltitude 0.041573167
groundAltitude 0.041522346
groundAltitude 0.041692957
groundAltitude 0.04158341
groundAltitude 0.041588604
groundAltitude 0.0415356
groundAltitude 0.041003928
groundAltitude 0.041549914
groundAltitude 0.04148855
groundAltitude 0.041550934
groundAltitude 0.041077018
groundAltitude 0.04108523
groundAltitude 0.041506946
groundAltitude 0.041449577
groundAltitude 0.04103347
groundAltitude 0.041456625
groundAltitude 0.041515626
groundAltitude 0.04091967
groundAltitude 0.04086396
groundAltitude 0.040993758
groundAltitude 0.04147093
groundAltitude 0.041468136
groundAltitude 0.0410633
groundAltitude 0.040940084
groundAltitude 0.04087811
groundAltitude 0.04094722
groundAltitude 0.040949546
groundAltitude 0.040885217
groundAltitude 0.041023366
groundAltitude 0.040957525
groundAltitude 0.040960893
groundAltitude 0.0415034
groundAltitude 0.040962383
问题是,为什么groundAltitude
而不是每个func update(deltaTime)
0.0?