# [Game AS1] Breakout Ball Movement

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.

``````MovieClip.prototype.checkWalls =
function(pGame) {
if (this.x<pGame.left+this._width/2) {
//when ball hits left wall
this.x = pGame.left+this._width/2;
this.vx *= -1;
} else if (this.x>pGame.right-this._width/2) {
//when ball hits right wall
this.x = pGame.right-this._width/2;
this.vx *= -1;
}
if (this.y<pGame.up+this._height/2) {
//when ball hits roof
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();
}
}
};
``````

After this.vy *=-1;
you need to calculate the distance from the centre of the bat
dx = (l+(bar._width/2)) - this.x;
then apply this to the amount the ball changes direction on the x-axis
this.vx = dx/bar._width //you might need to change that to suit