Skip to main content

Lesson 3: Turn to Heading

The [Turn to heading] block can also be used to turn the VR Robot. This block turns the VR Robot to a given compass heading between 0 and 359.9 degrees. When a VR Robot collides with a castle, it may be knocked off course. The [Turn to heading] block ensures the VR Robot will turn to face the next castle no matter what previously happened.

VR Robot inside a circle. The circle is labeled with degrees in 90 degree increments, beginning with 0 degrees at a 12 o'clock position, then 90 degrees at 3 o'clock, 180 degrees at 6 o'clock, and 270 degrees at 9 o'clock.

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.

Castle crasher playground in the shape of a square, with five castles present. There is one castle in each corner and one in the center of the square. The VR Robot is positioned at the center of the bottom wall of the playground, facing the center castle. Red callout boxes are around the middle castle and the bottom left castle.
  • Remove the bottom two blocks from the project.

    2 side by side VEXcode VR projects. The project on the left is the one from Lesson 2, with a red callout box on the bottom two blocks indicating they should be removed. The project on the right is the same project with those two bottom blocks removed.
  • Drag in the [Turn to heading] block and attach it beneath the [Drive for] block. Set the parameters of the [Turn to heading] block to 270 degrees.

    VEXcode VR project from above with a turn to heading block added at the bottom of the stack. The parameter in the block is set to 270 degrees. There is a red callout box around the block.
  • Drag in the [Drive for] block and attach it below the [Turn to heading] block. Set the parameters of the [Drive for] block to 700 millimeters (mm).

    VEXcode VR project from above with a drive for block attached to the bottom of the stack. The block reads drive forward for 700 mm. There is a red callout box around the block.
  • Select the “Open Playground” button to launch the Castle Crasher Playground if it is not already open.

    VEXcode VR Toolbar with a red box calling out the Open Playground button to the right side of the toolbar, between the Select Playground and Start buttons.
  • Select the “Start” button to test the project.

    VEXcode VR Toolbar with a red box calling out the Start button on the right side of the toolbar, between the Open Playground and Step buttons.
  • 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.

    Castle Crasher playground with the center castle crashed and the VR Robot facing the bottom left castle, which is also crashed.

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!

Castle Crasher playground with five castles, one in each corner. There are callout boxes on the upper left and middle castles. The VR Robot is in its starting position at the middle of the bottom wall of the playground, facing the center castle.

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.
  • Create this project by adding or removing the necessary blocks to the Unit2Lesson3 project. 

    VEXcode VR project begins with a When started block and has six blocks attached in the stack. From top to bottom the blocks read: Set drive velocity to 100%, set turn velocity to 100%, Drive forward for 200mm, Turn right for 180 degrees, Drive forward for 700mm, and Turn right for 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!

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf