2
我有一個對象與另外兩個對象發生衝突。我根據相關碰撞的物體改變恢復原狀。每當恢復原因從0.5變爲0時,它不會立即被識別出來,這會在歸還假設爲零時在短時間內引起反彈。我怎樣才能使變更立即被識別/生效?請參閱我的代碼如下:改變恢復聯繫/碰撞不立即生效
func didBegin(_ contact: SKPhysicsContact) {
var firstBody : SKPhysicsBody
var secondBody : SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
}
else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if firstBody.categoryBitMask == spriteCategory && secondBody.categoryBitMask == enemyCategory1 {
var spriteContactNode = firstBody.node
spriteContactNode?.physicsBody?.restitution = 0.5
self.physicsWorld.gravity = CGVector(dx: 0, dy: -2.0)
}
if firstBody.categoryBitMask == spriteCategory && secondBody.categoryBitMask == enemyCategory2 {
var spriteContactNode = firstBody.node
spriteContactNode?.physicsBody?.restitution = 0
self.physicsWorld.gravity = CGVector(dx: 0, dy: -0.5)
}
}