当动态物体掉落时,它的 `_ball.position.y` 值不会改变
when dynamic body falls down, its `_ball.position.y` value doesn't change
我的问题很简单 -
func setupScene() {
let sceneView = view as SCNView
sceneView.backgroundColor = SKColor.blackColor()
_scene = SCNScene()
sceneView.scene = _scene
sceneView.showsStatistics = true
// Scene gravity
sceneView.scene?.physicsWorld.gravity = SCNVector3Make(0, -70, 0)
sceneView.scene?.physicsWorld.speed = 2.0
sceneView.delegate = self
}
在某个时间点有 spawnBall 方法:
func spawnBall() {
_ball = SCNNode(geometry: SCNSphere(radius: 15))
_ball.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "ball")
_ball.geometry?.firstMaterial?.emission.contents = UIImage(named: "ball")
_ball.geometry?.firstMaterial?.emission.intensity = 0
_ball.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: nil)
_ball.physicsBody?.restitution = 0.1
_ball.physicsBody?.angularVelocity = SCNVector4(x: 1, y: 1, z: 1, w: 1)
let position = SCNVector3Make(0, 15*10, -200)
_ball.position = position
_scene.rootNode.addChildNode(_ball)
}
问题是 - 为什么当动态物体掉落时,它的 _ball.position.y
值没有改变?
我曾经 UIKit
当你移动 UIView
- 它的原点改变了(我假设看到类似的东西,因为我设置 _ball.position.y = 150 它应该下降)
以及如何观察它的运动?
它的 presentationNode
的 position
会改变。物理引擎保持模型值不变。
我的问题很简单 -
func setupScene() {
let sceneView = view as SCNView
sceneView.backgroundColor = SKColor.blackColor()
_scene = SCNScene()
sceneView.scene = _scene
sceneView.showsStatistics = true
// Scene gravity
sceneView.scene?.physicsWorld.gravity = SCNVector3Make(0, -70, 0)
sceneView.scene?.physicsWorld.speed = 2.0
sceneView.delegate = self
}
在某个时间点有 spawnBall 方法:
func spawnBall() {
_ball = SCNNode(geometry: SCNSphere(radius: 15))
_ball.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "ball")
_ball.geometry?.firstMaterial?.emission.contents = UIImage(named: "ball")
_ball.geometry?.firstMaterial?.emission.intensity = 0
_ball.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: nil)
_ball.physicsBody?.restitution = 0.1
_ball.physicsBody?.angularVelocity = SCNVector4(x: 1, y: 1, z: 1, w: 1)
let position = SCNVector3Make(0, 15*10, -200)
_ball.position = position
_scene.rootNode.addChildNode(_ball)
}
问题是 - 为什么当动态物体掉落时,它的 _ball.position.y
值没有改变?
我曾经 UIKit
当你移动 UIView
- 它的原点改变了(我假设看到类似的东西,因为我设置 _ball.position.y = 150 它应该下降)
以及如何观察它的运动?
它的 presentationNode
的 position
会改变。物理引擎保持模型值不变。