the below code detects the collision between two objects but it only changes direction only along the y-axis of the ball.can someone please help as to how to implement the sideways collision ?like if it hits on the side edges the ball direction should change on its x-axis only.
bricks.forEach(column=>{
column.forEach(brick=>{
if (brick.visible){
if(ball.x-ball.size>brick.x && ball.x+ball.size<brick.x+brick.w && ball.y+ball.size>brick.y && ball.y-ball.size<brick.y+brick.h)
{
ball.dy*=-1;
brick.visible=false;
}
}
})
})