SpriteKit physics in Swift - Ball slides against wall instead of reflecting

后端 未结 6 562
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 12:36

I have been creating my own very simple test game based on Breakout while learning SpriteKit (using iOS Games by Tutorials by Ray Wenderlich et al.) to see if I can apply co

6条回答
  •  一整个雨季
    2020-12-01 13:23

    This problem only seems to occur when the velocity is small in either direction. However to reduce the effect it is possible to decrease the speed of the physicsWorld, e.g.,

    physicsWorld.speed = 0.1
    

    and then increase the velocity of the physicsBody, e.g.,

    let targetVector = (moveToward - ball.position).normalized() * 300.0 * 10
    ball.physicsBody!.velocity = CGVector(point: targetVector)
    

提交回复
热议问题