Skip to main content

Lesson 3: Turning the VR Robot

Now that you have knocked over the first castle in the Castle Crasher Playground, you will need the VR Robot to turn to knock over another. This Lesson will walk you through the steps to turn the VR Robot and knock over two buildings on the Castle Crasher Playground.

Learning Outcomes

  • Identify how to use the [Turn for] block to turn the VR Robot right or left.
  • Identify how to use the [Turn to heading] block to turn the VR Robot to a given compass heading.

Rename the Project

  • If the previous lesson’s code is not already loaded, load the Unit2Lesson2 project.
  • Rename the project by selecting the project name box.

    VEXcode VR Toolbar with a red box calling out the project name box in the center. The project name reads Unit 2 Lesson 2.
  • Enter the new project name Unit2Lesson3, and select “Save.”

    Project name dialog box open with the new title, Unit 2 Lesson 3 typed. A red box calls out the Save option at the bottom of the project name dialog box.

Turn Right or Left

The [Turn for] block rotates the VR Robot a given number of degrees. This example will have the VR Robot drive forward to knock over the center building, reverse back to the start, then turn and knock over the building in the bottom right corner on the Castle Crasher Playground.

Top down view of the Castle crasher playground at the start, with five castles shown. The playground has one castle in each corner and one in the middle of the playground. The VR Robot is positioned centered against the back wall, facing the center. There are red callout boxes on the middle and bottom right castles.

For Your Information

To make a VR Robot turn at different speeds, the turn velocity can be increased or decreased using the [Set turn velocity] block.

Set turn velocity block with 50% in the parameter.
  • Drag in the [Turn for] block and attach it beneath the [Drive for] block. Set the parameters of the [Turn for] block to turn right 90 degrees.
    1. Note: This project has the [Set drive velocity] and [Set turn velocity] blocks added and set to 100%. These are optional blocks.

      VEXcode VR project beginning with a When started block. The blocks attached underneath, from top to bottom, are a Set drive velocity block with 100% in the parameter, a set turn velocity block with 100% in the parameter, a Drive for block set to drive forward for 800 mm, a drive for block set to drive reverse for 800 mm, and a turn for block set to turn right for 90 degrees. The turn for block has a red callout box around it.
  • Drag in the [Drive for] block and attach it below the [Turn for] block. Set the parameters of the [Drive for] block to 700 millimeters (mm).

    VEXcode VR project from above, with an additional drive for block attached. This block is set to drive forward for 700 mm, and has a red callout box around it.
  • 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 drive forward and collide with the center building before reversing back to the start. The VR Robot will then turn right 90 degrees and drive forward to collide with the building at the bottom right corner of the Castle Crasher Playground.

    VEXcode VR Castle Crasher Playground with the center castle crashed. The VR robot is at the bottom of the playground, facing the bottom right castle, ready to crash it.

Using Switch Blocks 

This is the Switch [Set turn velocity] block. Simply replace the numerical value by typing in a different number to change the block's parameter. 

Switch block with drivetrain.set_turn_velocity command typed in. The parameter after the open parenthesis reads 50, percent.

To convert an entire stack of VEXcode blocks to Switch blocks, simply select a VEXcode block and choose, "Convert Stack to Switch Block." The image below displays this Lesson's project as a Switch block. Each VEXcode block is converted into a Python command, and each command is listed inside one Switch block. 

When started block with a switch block attached. The six python commands for the project in this lesson are typed into the block, one on each line.

Select the Next button to continue with the rest of this Lesson.