0

I have been learning SpriteKit, and made a simple Pong game. However, when the ball is hit at a shallow angle to the wall, it does bounce back off like I would expect it to. The angle to the wall is probably about 5 degrees, but it still won't bounce.

The ball bounces fine off the wall if the angle isn't so small, so what might be causing this? Is there some minimum bounce setting I am able to adjust?

Here is the video

Thank you for anyone who can help me! :)

enter image description here

George
  • 25,988
  • 10
  • 79
  • 133
  • A code sample with the ball's physics would be helpful. – Hamer Apr 16 '18 at 17:45
  • @Hama The physics are not created pragmatically - updated question – George Apr 16 '18 at 18:32
  • It's been awhile since I've used SpriteKit but that seems correct. How about the SKPhysicsBody that it's colliding with? – Hamer Apr 16 '18 at 19:04
  • @Hama The bodies it contacts are completely fine as well, so I am not to sure what is going on – George Apr 16 '18 at 19:09
  • 1
    I think you're running into the same issue described [here](https://stackoverflow.com/questions/27671391/spritekit-physics-in-swift-ball-slides-against-wall-instead-of-reflecting). Hopefully that will point you in the right direction. Good luck! – Hamer Apr 16 '18 at 19:22
  • @Hama I have temporarily put the code from that question you linked into my question. As I am new to Swift, I can't seem to translate that code. It says there is no type obstacle, so I get rid of it and it complains about onCollision, and with a few other things. I appreciate the help! – George Apr 16 '18 at 19:57
  • @Hama So do you know how to fix this to Swift 4.0 as some of the methods do not work? Or am I forgetting to import some sort of library? – George Apr 17 '18 at 14:39
  • @George_E_2, your video clearly showed that you have used applyImpulse method. But your CGVector is not pong game like. I don't know what impulse you have given to the ball. I suggest you to use ball.physicsBody?.applyImpulse(CGVector(dx: 20, dy: 20)) – Imrul Kayes Apr 18 '18 at 15:24
  • I used a method similar to that - but the angle is randomised – George Apr 18 '18 at 15:34
  • this is a known issue with the physics in sprite kit, it uses a version of box2d that is not the current version which did fix the issue – Knight0fDragon Apr 20 '18 at 20:08
  • Obstacle is a custom object, in your case most likely SKSpriteNode – Knight0fDragon Apr 20 '18 at 20:09
  • @Knight0fDragon It doesn't make the ball bounce back – George Apr 20 '18 at 20:56

0 Answers0