[Q7.5.1]: Will the solution we have devised in the previous section work for all situations where we want one actor to approach another, stopping at a reasonable distance for conversation? Please Explain
Our calculation, specified when the program was written but not executed until the program was run, allows for the total distance between the two actors to change. But, it might not look realistic if the size of the objects change. This is a problem. The "comfortable distance" for speaking with another person is measured from skin surface to skin surface (sort of), not from the centers of the two objects.
To check this out, open the world AngelAndCoach. Look at the line of code in World.My first method - it moves the Angel to the Coach in the same way as we previously had the Angel move to the Egyptian.
Run the program to see the Angel move to the Coach. It's a little close for comfort, isn't it, with the Angel's wing and the Coach's arm overlapping!
Let's be precise, then, and change our "-1" calculation to be based on this "comfortable distance" - let's say 0.5 meters from skin surface to skin surface.
[Q7.5.2]: Write down in English, or as a piece of arithmetic, what you need to do to calculate the right distance for the Angel to move, given that you now want the Angel and Coach to be 0.5 meters from each other from skin to skin. You can assume that the distance from the center of an object to its skin, or edge, is half of its width.
Let's create a new move...towards... tile using the calculation you've just written down. It can take a while to build up a calculation this big, so take your time, and follow the steps carefully (it's also really helpful to have the calculation actually written out on paper). You build up the calculation from left to right - but take care over the parentheses...
Let's start adding the instructions to our program (Alice world).
Select the Angel object.
2. Drag the move...towards... tile from the angel's details into World.My first method.
A. Set the parameters to 1 meter and the entire coach for now.
Next we need to set the distance between the two objects.
3. Select the functions tab in the angel's details pane (lower left corner).
4. Drag in the angel distance to function, dropping it on the 1 meter parameter of the move...towards... method call.
A. Select the coach, then the entire coach as the parameter to the function.
We will not take off half the Angel's width
5. Click the little down arrow/triangle to the right of the distance to function tile.
A. Select math, then the angel distance to coach - (minus) operation, then select 1 for now.
6. Drag over the Angel's width function, dropping it onto the 1 meter you just selected.
7. Click on the down arrow to the right of the width function, selecting math, then angel's width / (divide), then 2.
A. You can see by the parentheses that Alice has put in that you have the right calculation:
(angel distance to coach - (subject = angel's width / 2)
So far so good.
8. Take off half the Coach's width (note that if the calculation is getting too wide for your window, you can scroll it left and right with the scroll
bar at the bottom of the code window)
A. Click the down arrow at the right hand side of the whole amount = parameter (the purple tile), then math, then - (subtract) and finally 1 meter again.
9. From the tiles of the Coach's Details pane, drag over the Coach's width function, dropping it onto the 1 meter you just selected.
A. As before, click on the down arrow to the right of the width function, selecting math, coach's with /, then 2 as before.
B. Again, you can check the parentheses to see that this is the calculation you want.
This would get the two objects touching at their edges (you could run it to see if that's right). So now take off the "comfortable space" of 0.5 meters.
10. Click on the down arrow at the right of the whole amount = parameter (the purple tile), then math, ((angel distance to coach-(angel's width/2))-(coach's width/2)) - (minus sign), then 0.5 meters.
Phew. You should be done!
Run this code to convince yourself that it works as expected. (Delete the original move...towards... tile that you created before.) Try changing some of the values, predicting what you think will happen.
Make sure to save the World you created on this Page.
Recommended File Name is LastName-FirstName-7.5 AngelAndEgyptianMathExpression.a2w