【发布时间】:2016-03-26 05:53:24
【问题描述】:
我正在评估 iOS SpriteKit 物理引擎,为了测试,我使用 Xcode 创建了一个包含两个圆形节点的简单场景:
两个节点都有圆形的物理体和 5 公斤的质量。
我用SKPhysicsJointSpring 连接两个节点。这是整个设置(viewDidLoad()):
let path = NSBundle.mainBundle().pathForResource("MyScene", ofType: "sks")!
let scene = NSKeyedUnarchiver.unarchiveObjectWithFile(path) as! SKScene
let border = SKPhysicsBody(edgeLoopFromRect: scene.frame)
border.restitution = 0;
border.friction = 0;
scene.physicsBody = border
let player = scene.childNodeWithName("player")! // large ball
let tail1 = scene.childNodeWithName("tail1")! // smaller ball
player.physicsBody!.usesPreciseCollisionDetection = true
tail1.physicsBody!.usesPreciseCollisionDetection = true
let spring1 = SKPhysicsJointSpring.jointWithBodyA(player.physicsBody!, bodyB: tail1.physicsBody!, anchorA: player.position, anchorB: tail1.position)
spring1.damping = 1
spring1.frequency = 3
scene.physicsWorld.addJoint(spring1)
spriteKitView.presentScene(scene)
注意:在场景编辑器中重力设置为 (0,0)。
当我移动较大的节点时(例如,通过使用 touchesBegan() 捕获触摸并将节点的位置设置为触摸位置),另一个根据弹簧参数跟随。
但是,如果我移动节点的速度足够快,以至于弹簧力变得极端,那么当弹簧收缩时,两个节点都会重叠。我希望它们相互碰撞,因为它们的collisionBitMask 默认设置为-1(所有位设置)。我启用了usesPreciseCollisionDetection,但效果仍然可见。
当我在场景周围添加一个边缘循环时,它们确实会按预期与该边缘发生碰撞。与具有物理主体(但未连接关节)的其他节点相同。
我的印象是弹簧的存在以某种方式使引擎忽略了与关节连接的节点之间的碰撞。 其他人也观察到这一点吗? 我忘了什么吗?还是按预期工作?
【问题讨论】:
标签: ios collision skphysicsbody skscene