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.
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:
- We can also see that the input angle (or the symmetric, which is the same) plus the output angle add 180º:
- 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º:
- 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:
- 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
Challenge 1:
Modify the m2repte31 project so that whatever the input direction there is, a natural rebound of the ball against the racket.
Track: To find out in what direction a person is oriented we have to use this blog:
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?
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º:
- 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:
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.
Track: 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?
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.
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