Lesson 3: Turn to Heading
The turn_to_heading command can also be used to turn the VR Robot. This command turns the VR Robot to a given clockwise heading between 0 and 359.99 degrees. When a VR Robot collides with a castle, it may be knocked off course. The turn_to_heading command ensures the VR Robot will turn to face the next castle no matter what previously happened.

This example will have the VR Robot move to knock over the center building, then turn and knock over the building in the bottom left corner on the Castle Crasher Playground.

-
Remove the bottom two commands from the project. Your project should now look like this:
# Add project code in "main" def main(): drivetrain.set_drive_velocity(100, PERCENT) drivetrain.set_turn_velocity(100, PERCENT) drivetrain.drive_for(FORWARD, 800, MM) drivetrain.drive_for(REVERSE, 800, MM) -
Drag in or type the turn_to_heading command after the drive_for command. Set the parameters of the turn_to_heading command to 270 degrees. Your project should now look like this:
# Add project code in "main" def main(): drivetrain.set_drive_velocity(100, PERCENT) drivetrain.set_turn_velocity(100, PERCENT) drivetrain.drive_for(FORWARD, 800, MM) drivetrain.drive_for(REVERSE, 800, MM) drivetrain.turn_to_heading(270, DEGREES) -
Drag in or type the drive_for command and attach it below the turn_to_heading command. Set the parameters of the drive_for command to drive forward 700 millimeters (mm). Your project should now look like this:
# Add project code in "main" def main(): drivetrain.set_drive_velocity(100, PERCENT) drivetrain.set_turn_velocity(100, PERCENT) drivetrain.drive_for(FORWARD, 800, MM) drivetrain.drive_for(REVERSE, 800, MM) drivetrain.turn_to_heading(270, DEGREES) drivetrain.drive_for(FORWARD, 700, MM) - Select the “Open Playground” button to launch the Castle Crasher Playground if it is not already open.

- Select the “Start” button to test the project.

-
Watch the VR Robot move forward and collide with the center building before reversing back to the start. The VR Robot will then turn to a heading of 270 degrees and drive forward to collide with the building at the bottom left corner of the Castle Crasher Playground.

Mini Challenge
For this mini challenge, the VR Robot should collide with the middle building and the building on the top right of the Castle Crasher Playground. You will be given a project, but there is an error. Edit the project to solve the mini challenge!

Follow these steps to complete the mini challenge:
-
The video clip below shows how the VR Robot should move to topple both sets of blocks. The robot should drive straight ahead through the middle set of blocks to knock them over, then turn right and drive forward into the top right set of blocks to topple them as well.
Video file -
Create this project by adding or removing the necessary commands to the Unit2Lesson3 project.
# Add project code in "main" def main(): drivetrain.set_drive_velocity(100, PERCENT) drivetrain.set_turn_velocity(100, PERCENT) drivetrain.drive_for(FORWARD, 1550, MM) drivetrain.turn_for(RIGHT, 180, DEGREES) drivetrain.drive_for(FORWARD, 700, MM) drivetrain.turn_for(RIGHT, 90, DEGREES) - Start the project to see where the error is in the code.
- Edit the code and try again. Continue this process until the mini challenge is complete.
- Once the VR Robot successfully collides with the middle building and the building on the top right of the Castle Crasher Playground, save the project.
- Save the project before moving on.
Congratulations! You solved the mini challenge!