Session 3: Different rackets, different bounces

Work plan

  • Types of rebounds
  • Angles
  • Character twists

Natural bounce

In the previous session we have seen how we can make the ball bounce with the racket, however, we have programmed it so that the ball goes in the opposite direction or bounces by taking a random direction. With neither of the two options the ball does a natural rebound, as he would do to reality.

Step by step Let’s do it step by step

  • Entering our Scratch account, we open the m2repte21 project and set it as m2repte31
  • To calculate the output direction of the ball, we must take into account that the input angle must be the same as its symmetrical angle, as we see in this image:
    Input angle = symmetrical angle
  • We can also see that the input angle (or the symmetric, which is the same) plus the output angle add 180º:
    Output angle = 180 - input angle
  • We can calculate, then, the angle of exit of the ball with the formula angle of exit = 180 – angle of entrance . For example, by an angle of entrance of 60º would correspond an angle of exit of 120º
  • Note, however, that the value of the angle is not the same as the direction of the character . If we remember “the rose of the winds” of the directions of the characters of the Scratch, by an angle of entrance of -135º would correspond an angle of exit of -45º:
    Rose of the Winds Directions entrance and exit
  • If we apply the formula above to the values of the directions of the “rose of the winds” we will find that exit angle = 180 – (-135) = 315 (let’s look at that when we have two remains, in fact what we do is add) . However, these 315º are not the -45º that we anticipate in the “rose of the winds” of the directions
  • What happens is that this “rose of the winds” of the directions is not fixed, it is cyclical, and can take different values:
    Rose of Cyclic Winds
  • So, the 315 degrees that we have obtained as a result of the formula correspond to the -45 degrees we had foreseen that we would obtain as a result
  • Let us note that in any of the values of the “rose of the winds” of the directions we can add or subtract 360, which are the degrees that have a whole circle of circumference, and will continue to function correctly

Icon challenge Challenge 1:

Modify the m2repte31 project so that whatever the input direction there is, a natural rebound of the ball against the racket.

Icon trackTrack: To find out in what direction a person is oriented we have to use this blog:
Management


What if the racket is vertical?

We have seen how we can do to control the rebound of the ball when the racket is horizontal. Is the solution always the case?

Step by step Let’s do it step by step

  • We continue with the m2repte project31
  • We duplicate the character of the racket and, from the dressing tab we select it and rotate it 90º:
    Selected racket
  • Let’s now make the program of this vertical racket so that the ball has a natural rebound. If we look at the “wind rose” of the directions we will see that the formula we have done before now does not serve us
  • However, if we look closely we can see that when the input address is 135 the output must be -135 and vice versa. We verify if this works for any direction of entry:
    Vertical racket

Icon challenge Challenge 2:

Let’s change the m2repte31 project so that we have both visible rackets (horizontal and vertical) and, whatever direction of entry, there is a natural rebound of the ball against the racket.

Icon trackTrack: The horizontal racket is already solved. For the vertical racket, what operation can we use to convert a number into the same number but with the sign changed?


Icon project Our project grows …

Now that we have seen how we can bounce the ball naturally by controlling the angle of entry and the exit angle, we must decide which obstacles we will add to our  pinball  where the ball will rebound while moving. These obstacles will be, in fact, characters that we can draw, choose from the gallery or upload through a photograph. We must add to the definition of our project the obstacles that we will add and where we will place them.


Glossary icon Because we are programmers and programmers we talk about …

  • Angle of entry: angle that forms the ball with the racket when it arrives.
  • Output angle : angle that forms the ball with the racket when it is bounced. It is calculated by subtracting the input angle to 180º.
  • Compase rose : scheme that allows us to find the equivalence between the output angle that we have calculated and the direction of the characte