[Pong game] How do I make the ball bounce off with an unpredictable angle?

WitlessWonderer

• Posts: 35
Ceosol, what kind of unwanted occurrences are you talking about?  What would happen?

ceosol

• Posts: 2279
Box2D does not seem to know how to handle two moving objects colliding. I would get the ball sometimes bouncing backwards, ending up going behind the paddle. Other times, the ball would get an insane speed up boost, making it impossible to play. The worst one was deflecting into a horizontal trajectory, basically bouncing back and forth on its own forever. Because that last scenario happened so frequently, I had to implement a test where if the ball had a horizontal motion for more than 1 second straight, it would get bumped downward.

treaxen

• Posts: 29
I don't think I have much time to do other things... assignment due in like 4 days

treaxen

• Posts: 29
Box2D does not seem to know how to handle two moving objects colliding. I would get the ball sometimes bouncing backwards, ending up going behind the paddle. Other times, the ball would get an insane speed up boost, making it impossible to play. The worst one was deflecting into a horizontal trajectory, basically bouncing back and forth on its own forever. Because that last scenario happened so frequently, I had to implement a test where if the ball had a horizontal motion for more than 1 second straight, it would get bumped downward.
it was due to the horizontal trajectory that I wish to let the ball have a random reflecting angle. On the other hand, I am also having a problem of the ball going right past the paddles, it happens only with one side of the paddle tho.
Besides, any idea how to make the ball being unable to be pushed by the paddles? Enabling "cannot be pushed" option will take away the ball's ability to collide with anything, but I need to make it not pushable as  there are times when I squeezed the ball right out of the screen with the paddles

danegony

• Posts: 22
hit 1P 2 times set x-speed to 30        -30 -> 30 -> 30
left         right     right
hit 1P 2 times set x-speed to negate x-speed of self     -30 -> 30 -> -30
left      right     left
How you think?
This block existed when you using sensor.

« Last Edit: February 10, 2016, 04:02:25 am by danegony »

treaxen

• Posts: 29
hit 1P 2 times set x-speed to 30        -30 -> 30 -> 30
left         right     right
hit 1P 2 times set x-speed to negate x-speed of self     -30 -> 30 -> -30
left      right     left
How you think?
This block existed when you using sensor.
sorry but..I don't quite understand what you mean >_<

treaxen

• Posts: 29
Hi guys, thanks for the help, my problem is kinda solved now. Used ceosol's suggestion (english paddle deflection) in the end, tweaked my other blocks for a bit and it worked pretty well. I only have to deal with the random bugs of the ball flying  out of screen from time to time and the paddle being able to push+accelerate the ball

ceosol

• Posts: 2279
Make the paddle "cannot be pushed" and make the ball a normal collision (not a sensor). If you used my method, the ball is always reset to the speed that you have input.

• Posts: 2720
I only have to deal with the random bugs of the ball flying  out of screen from time to time and the paddle being able to push+accelerate the ball
I would convert the paddle to a sensor:

<a href="http://static.stencyl.com/games/33456-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/33456-0.swf</a>
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

treaxen

• Posts: 29
I would convert the paddle to a sensor:

If I were to make the paddles a sensor, the green collision blocks (used in ceosol's suggestion) will not work. Kinda fixed it by making the ball unpushable while fixing the paddle's x-position. Pretty interested in how u made your game tho

treaxen

• Posts: 29
Make the paddle "cannot be pushed" and make the ball a normal collision (not a sensor). If you used my method, the ball is always reset to the speed that you have input.
not sure man, i made it exactly like yours, it ended up accelerating. It's sort of fixed now though, thanks