# GMLMy ball keeps getting stuck to the wall and paddles[GM:S]

Y

#### Yumeito

##### Guest
I'm making a pong like game for android and I've got some issues with collisions between the ball and walls and between the ball and paddles.

The ball keeps getting stuck at corners and also in between the paddle and the wall...

Here's what it looks like getting stuck at a corner : https://streamable.com/kf006

Sometimes the ball also gets stuck at the tip of the horizontal wall : https://streamable.com/lvnta

This is what it looks like getting stuck with the paddle : https://streamable.com/5qyk8

This is what the room looks like: http://imgur.com/a/ptILL (the yellow lines are the wall objects)

The ball also get's stuck with the player paddle but when that happens if the player moves the paddle the ball continues moving...In case of the AI paddle, the AI won't move once the ball is stuck...I want to prevent it from getting stuck with either of the paddles...

My collision code between the ball and wall :

This code is insde the ball object, inside a collison event with the wall
Code:
``````//Move the ball back to where it's not colliding with the wall
x = xprevious;
y = yprevious;

//Horizontal collision
if ( bbox_bottom >= other.bbox_top ) and ( bbox_top <= other.bbox_bottom ) {
direction = 180 - direction;
//Vertical collision
} else if ( bbox_right >= other.bbox_left ) and ( bbox_left <= other.bbox_right ) {
direction = -direction;
}

//Prevent Ball from getting stuck at a corner
if ((x <= 180) and (y >= 1600)){
randomize();
direction =  random_range(10, 80);
}
if ((x >= 900) and (y >= 1600)){
randomize();
direction =  random_range(100, 170);
}

if ((x <= 180) and (y <= 300)){
randomize();
direction =  random_range(280, 350);
}
if ((x >= 900) and (y <= 300)){
randomize();
direction =  random_range(190, 260);
}``````
those x and y cords are close to the corner of the walls...

My collsion code between ball and AI:
Code:
``````direction = point_direction(x, y, other.x, other.y)+180;
vspeed = max(15,abs(vspeed));``````
My collsion code between ball and player:
Code:
``````direction = point_direction(x, y, other.x, other.y)+180;
vspeed = min(-15,-1*abs(vspeed));``````
The ball and the paddle has precise collision enabled.

Sometimes the ball just shoots out of the room : https://streamable.com/az0bp

The wall objects are not solid.

The ball continues to animate even after it gets stuck. The balls animation is controlled by the balls direction and speed...so I think that means that the ball still has speed after it gets stuck....

Balls animation code, inside the step event of ball object :
Code:
``````//Animation
image_angle = direction;
image_speed = speed;``````
GM:S v1.4.1763