# \[Game AS1\] Breakout Ball Movement

**URL:** <https://forum.kirupa.com/t/game-as1-breakout-ball-movement/313748>\
**Category:** programming\
**Created:** [September 8, 2010, 5:08pm UTC](https://forum.kirupa.com/t/game-as1-breakout-ball-movement/313748 "2010-09-08T17:08:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjj](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@cjj](https://forum.kirupa.com/u/cjj)\
**Post date:** [September 8, 2010, 5:08pm UTC](https://forum.kirupa.com/t/game-as1-breakout-ball-movement/313748/1 "2010-09-08T17:08:23Z")

</div>

Hi. I have a breakout game that I created following a tutorial.

The problem that I have is the ball movement isn’t very ‘natural’ as it only really moves one way. When the ball hits the paddle it doesn’t bounce off in different directions depending on where it hits the paddle it always bounces off in the same direction.

In most breakout games I’ve seen the ball bounces off the paddle at different angles. I was hoping that someone could perhaps help me with this problem. I would be so grateful.

My ball hit code is as follows.

[LEFT]

```auto
MovieClip.prototype.checkWalls = function(pGame) { 

    if (this.x<pGame.left+this._width/2) {
        this.x = pGame.left+this._width/2;
        this.vx *= -1;
    } else if (this.x>pGame.right-this._width/2) {
        this.x = pGame.right-this._width/2;
        this.vx *= -1;
    }

    if (this.y<pGame.up+this._height/2) { 
        this.y = pGame.up+this._height/2;
        this.vy *= -1;
    } else if (this.y>pGame.barLevel-this._height/2) {
        //Determine what happens when ball hits paddle
        var l = bar._x-bar._width/2;
        var r = bar._x+bar._width/2;
                
        if (this.x>l && this.x<r) {
            this.y = pGame.barLevel-this._height/2;
            this.vy *=-1;
        } else {
            pGame.loseLife();
        }
    }
};

```

[/LEFT]
