Error that keeps moving only up and down or side to side in BreakOut

Hello.
I am making a game like BreakOut.
But I have a problem that I haven’t solved.
If there are no blocks to break, when I hit the ball with the paddle, it doesn’t change direction and just stays up and down, especially on mobile touch.
So I’ve tried using the events below, but it doesn’t fix it.
It also causes it to bounce back and forth between the left and right walls dozens of times.

Is there a workaround for this?

Event >
Apply force at a random angle if the ball’s angleForce is less than or equal to 20 degrees or greater than 160 degrees.
If the ball’s angleForce is 270 degrees, apply force at a random angle.



I have no idea what is going on there
Even better your issue makes no sense like there should be no way it happens since you are not checking anything against blocks
So WTF?

But here is breakout example
Maybe it can help you?

No matter how much I try to steer the ball sideways when I touch the paddle, it keeps going up 270 degrees (assuming there are no block in the way).

We asked for a solution to the same repetitive continuity of the ball’s movement with or without blocks in the path of the ball, and based on the game example you provided.


I used physics only once in my life
And i get it to work by changing everything in settings window until it did work as i wanted
So i am no expert

But tell me why you are using abs?
abs is removing - sign from number so if you have -256 then abs(-256) = 256

Now angle in gdevelop goes either 360° or
image

So in this case you would want anything but abs

Another thing you can try is put text object on your scene and change text of that text object to

"Angle velocity "+ToString(Ball.Physics2::LinearVelocityAngle())+"
AngleForce "+ToString(abs(Ball.Physics2::LinearVelocityAngle()))

And now you will see exactly what each value is at the time

Where why you change in last event Y velocity?
Shouldn’t you be changing Y an X velocity and not only Y?
Again i have no idea if its right or wrong
Like i said i used physics only once

I am not sure if LinearVelocityAngle even shows angle of movement
But speed of movement
AGAIN I AM NOT SURE but the longer i look at it more i believe you are checking and affecting speed and not actual ball angle

I did the same thing as indicated in the sample game event, where the comment in the event said this was the reason.


Avoid the ball getting stuck. So, that it won’t go back and forth in the same direction. The physics engine doesn’t have an expression/condition to check the angle of the force of an object (Here, it is the ball). So, we use some maths to get the angle of movement from the velocity on each axis. The calculation returns a negative value for reflex angles (greater than 180). We can’t use negative angles as we need to calculate if the movement is -170 and 170 (190 and 170) that is > -170 and > 170, it won’t work. So, we use the absolute value of the angles to find the angle.

So put both LinearVelocityAngle and Angle force to text object and look what they actually display

And, I’d like to be able to redirect and get the ball out of the way when this happens, but I can’t.

I really have no idea what is wrong here

I would create new scene and try to copy events from example i sent in my 1st message
Then see after adding which it stops working and try to deduce the problem
Or maybe it would solve the problem

The ball is stuck between the block and the top of the wall, so it’s only doing vertical motion.
I’d show you a video, but I can’t embed it, so here’s an image.

The ball is trapped. The game cannot progress further. Both the block and the wall are static. I’m looking for a way to get the ball out in this case. So I wanted to use an event that would unconditionally change the angle of the ball when it travels 270 degrees (-90 degrees). But it doesn’t work. If the block and the wall collide twice at the same angle (270 degrees), what event could force the ball to change direction?

I get your idea now

BUT are you 100% sure you are checking right value?

I would put it to text object to see what is actual vertical position

AND you could
A way to fix this would be to check if ball X position
For example store its X position information into variable called BallXPos
And check how many times ball hit wall or other block
Like each time ball hit wall or block you add 1 to variable
Let’s call this variable HitCount

Now
3 things

1 - You check if BallXPos is +/- 10 for example
Condition
Variable BallXPos is less than Ball.X()-10
Variable BallXPos is greater than Ball.X()+10

Action
Change Variabe BallXPos set to Ball.X()
Change variable HitCount SET TO 0

2 - You actually count ball hits

Condition
Ball is in collision with block
Trigger once

Action
Change variable HitCount ADD 1

3 - Last event
Condition
Variable BallXPos is less than Ball.X()-10
Variable BallXPos is greater than Ball.X()+10
Variable HitCount is greater than 6

Action
And here you add some impuls to your ball in some horizontal angle

And so if position of ball changed more than 10 pixels to the left or right
NEW X position of ball will be saved to variable
And HitCount variable will be set to 0

IF ball keep colliding with blocks more than 6 times while its X position will not go up or down for 10 pixels (meaning it is stuck in situation you describe)

Then you add force/impuls or whatever to give it push in some horizontal angle

1 Like

I created the event with your help, but the problem is the same. What went wrong?

ballXPoss: Scene Variable
HitCount: Object Variable

The same issue occurred when the ball collided with the paddle,
The ball’s colliding body is conditioned by the paddle

This is getting stupid like WTF?

Check this out
I went into this example
I literally set ball to start by going 90°

BUT before that i disabled the event which should NOT allow it to go in straight vertical line

AND IT STILL DO NOT GO IN STRAIGHT VETICAL LINE WTF?!

And i did try 1st to send it -90° and it still did not allow me
That is why on 1st screenshot i try 90°

Now i assume there is some other event that is causing it
And this one

Have nothing to do with it
That is why it is not working for you

Now i have idea
Can you just rotate your ball to the angle it is flying?
And if ball angle is -90° or 90°
You would then simply add some push in different angle?
Or like just actually use this acrtion

And now your ball would NEVER go in straight line

MAYBE not - + 30 but 10 would be enough