Bouncing Ball SKPhysicsBody - Stop Bouncing Perpendicular Forever
<p>So I'm making a brick break style game using "<a href="https://www.raywenderlich.com/123393/how-to-create-a-breakout-game-with-sprite-kit-and-swift" rel="nofollow">Ray Wenderlich's amazing tutorial</a>" in <code>Spritekit</code>/<code>Swift</code>, just like the tutorial.</p>

<p>I successfully have a ball bouncing around the screen using a <code>SKSpriteNode()</code> and <code>SKPhysicsBody()</code> and I've been tweaking values for the <code>impulses</code> used to begin the ball bouncing around the screen forever.</p>

<p><strong>However</strong>, I stumbled upon a problem which I hope to find a solution.</p>

<p>Sometimes, in my game, the <code>Sprite</code> will bounce around and become "<strong>Wall Locked</strong>" bouncing almost Perpendicular (or straight) between two walls, (give or take a few pixels)! So ends up Zig-Zagging across the whole screen between two said walls for ages.</p>

<p>What I want to do is, should this happen and the ball get "Wall Locked" to introduce a new impulse to get it moving again...</p>

<p>How can this be done? For example, if it has bounced between the top and bottom walls 10 times, then it's time to adjust it's angle/introduce a new impulse.</p>

<p>Could the last 10 positions be stored in an array, then test if their almost perpendicular somehow?</p>