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

treaxen

  • Posts: 29
Hi guys, newbie here,
So I was making a pong game, but for my work I find that the ball bounces of in an angle which is a little too predictable, which is the negative of the angle of incidence

the command I used was [set x-speed to [negate[x-speed of self]]

which means that my ball will only bounce off to -30 degrees if it comes from an angle of 30 degrees, it makes the game predictable, and boring. The worst is when to comes in at 0/180 degrees, the loop will go on forever.

So i would like to know, what can I do to alter the angle of the reflected ball randomly? Such as when the ball comes from an angle of 30 degrees, it has chance to bounce off towards -30 degrees, -45 degrees or -15 degrees.

I will appreciate any help, thank you

yoplalala

  • *
  • Posts: 1502
maybe  set x-speed to negate (  random number bewteen  ( x-speed-15) and ( xspeed +15)). I don't know but you should use randoms ;)

treaxen

  • Posts: 29
maybe  set x-speed to negate (  random number bewteen  ( x-speed-15) and ( xspeed +15)). I don't know but you should use randoms ;)
Hi, thanks for the reply,

Unfortunately it did not work, the only thing it does is slow down the ball Q_Q

LIBERADO

  • *
  • Posts: 2646
Can you show us a screenshot of your code?
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
Can you show us a screenshot of your code?
Here's the screenshot of the code which activates when the ball hits one of the paddles.

LIBERADO

  • *
  • Posts: 2646
Install the EasyMath extension: http://community.stencyl.com/index.php/topic,27769.0.html

Then, in your current code, insert this block:
   

IMPORTANT: You must insert it just below your "set [x-speed]..." block.
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
Install the EasyMath extension: http://community.stencyl.com/index.php/topic,27769.0.html

Then, in your current code, insert this block:
   

IMPORTANT: You must insert it just below your "set [x-speed]..." block.
If I install the plugin, will it be a problem if I open up the file in other computers? Because I will need to send it to my lecturer for grading.

LIBERADO

  • *
  • Posts: 2646
You will need to install the EasyMath extension in other computers, too.
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
My lecturer told me to try not to use a plugin for my project...
I tried to look for something to replace the blocks needed, which is the [direction of actor] block. It seem to work with the borders, other blocks except for the paddles. The ball will now only collide with one side of the paddle, the right side of them and it will just go through the paddles if the ball comes from the left side. Any idea what caused it?

screenshot of the blocks:

For other objects:


For the player paddles (as the paddle has both sides, i had to cover for them both):



tigerteeth

  • Posts: 734
Another approach would be to change the collision polygon of the paddle every few seconds.

ceosol

  • *
  • Posts: 2254
The way the early developers dealt with these types of issues was implementing an "English" deflection. Don't ask me why it was called English, it does not make sense to me.

Basically, English paddle deflection means the ball bounces in a certain direction depending on where it hits on the paddle. Say your paddle is 100 pixels long. If the ball hits from:
1-20, deflect at a -60 degree angle
21-35, deflect at -45
36-50, deflect at -30
51-65, deflect at 30
66-80, deflect at 45
81-100, deflect at 60

This makes the angle harder to determine, but also allows the user to increase their skill at paddle placement. You do not need any extra special stuff for this to work. And you won't be hitting any 0 degree deflections since 0 is not one of the possibilities.

hendriza01

  • *
  • Posts: 82
The way the early developers dealt with these types of issues was implementing an "English" deflection. Don't ask me why it was called English, it does not make sense to me.

Basically, English paddle deflection means the ball bounces in a certain direction depending on where it hits on the paddle. Say your paddle is 100 pixels long. If the ball hits from:
1-20, deflect at a -60 degree angle
21-35, deflect at -45
36-50, deflect at -30
51-65, deflect at 30
66-80, deflect at 45
81-100, deflect at 60

This makes the angle harder to determine, but also allows the user to increase their skill at paddle placement. You do not need any extra special stuff for this to work. And you won't be hitting any 0 degree deflections since 0 is not one of the possibilities.

Wow nice! Thinking of some ways to use that, great share thanks ceosol :)

treaxen

  • Posts: 29
The way the early developers dealt with these types of issues was implementing an "English" deflection. Don't ask me why it was called English, it does not make sense to me.

Basically, English paddle deflection means the ball bounces in a certain direction depending on where it hits on the paddle. Say your paddle is 100 pixels long. If the ball hits from:
1-20, deflect at a -60 degree angle
21-35, deflect at -45
36-50, deflect at -30
51-65, deflect at 30
66-80, deflect at 45
81-100, deflect at 60

This makes the angle harder to determine, but also allows the user to increase their skill at paddle placement. You do not need any extra special stuff for this to work. And you won't be hitting any 0 degree deflections since 0 is not one of the possibilities.
Hi, is it possible for you to give me some tips on how to achieve that? I am completely new to the coding world...

ceosol

  • *
  • Posts: 2254
I just did it like this. The paddle is on the bottom of my screen, facing up. That is why the velocity angles are between 0 and -180.

treaxen

  • Posts: 29
I just did it like this. The paddle is on the bottom of my screen, facing up. That is why the velocity angles are between 0 and -180.
I don't really understand the code, what does the "[x of self]+[number]>[x-center] of [other actor]" means?