Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
14.5. Avoiding Collisions
You can use conditionals to detect when two turtles are getting close to each other and then have the turtles take evasive action. In the code below they try both try to turn right just as ships do if they are heading straight for each other.
Run the program below. Notice that this code doesn’t quite work as intended. Both jaz and mia turn completely around. How could you modify the code to fix it so that they turn to avoid each other, but don’t end up turning completely around? You might want turn only if the distance between the x values and the y values is less than some amount. If you have trouble figuring out a solution, click on the tab to view one way to solve this.
Note
Discuss topics in this section with classmates.
You have attempted
of
activities on this page