Physics detecting collision multiple times

前端 未结 2 1047
醉酒成梦
醉酒成梦 2020-12-21 11:09

When the ball collides with the cup, the score should increase by 1. However it currently increases by 1, 3 or sometimes 4 which means the collision is being detected multip

2条回答
  •  失恋的感觉
    2020-12-21 11:43

    this happened to me, what to do is simple, just define everything like this each node needs one: first make this for the nodes, either if its a screen border or what ever node it hits, say this:

    let nodesCatergory : UInt32 = 0x1 << 1 
    

    after, put this nodesCatergory to everynode you have in game, or the nodes that it collides with, then add it like this:

    if firstBody.categoryBitMask == ballCategory &&       secondBody.categoryBitMask == nodesCatergory {
    //score++
    println("point scored, NOT!")
    //moveBall() //Move ball back to start position
      }
    

    thats it! you can do these till the desired effect is acquired!

提交回复
热议问题