Unity – Lab 2: Robot Arm


Please submit on Canvas before the start of your lab

  • Download the code for the lab and make sure you can open it in Unity using version 2020
  • Answer the 2 questions below


Examples of rotating around 3D axis

x: somersault (forwards/backwards)

y: spinning in circles with your arms out (like a top)

z: cartwheel (left/right)


  1. If we want this object to rotate down towards the ground (in the direction of the blue arrow) which axis should we rotate around (x,y, or z)?
  2. What is the definition of an algorithm? Provide an example of an algorithm to move an arm for a specific purpose (e.g. reaching for an object, throwing a ball, etc.). Plain English description (ie: no code or pseudo-code) is fine.


The goal in all 3 sections of this lab is to give the arm the correct instructions to get it to hit the target (small ball).

Part 1: Hitting a single target

  1. Open scene 2 –> Part 1
  2. Figure out how to rotate the arm to hit the blue ball
    1. Open the “Part1RotateArm” script
    2. In the Start() function, make the arm rotate by writing “ArmMovementList.Add(new Vector3(x,y,z)” where x,y,z are the amounts (in degrees) you want to rotate the arm around each axis
      • Note that the arm is currently facing towards the Z axis (blue arrow) (forward is the direction the little knob on top is pointing)
      • Each movement is added to a list, which are then performed in order one at a time
      • It is easier to rotate one axis at a time
      • Not sure which axis to rotate? Try fiddling around with the arm first in the scene view

Part 2: Hitting 3 targets

  1. Open scene –> Part 2
  2. Figure out how to make the arm hit all 3 balls
    1. Open the “Part2RotateArm” script
    2. Use the same code instructions as in part 1 to get the arm to move
    3. Notice that the axis change when you rotate. How can you still find the correct rotation?
      • Hint: Find a way to reset the rotations you make before moving to the next target

Part 3: Getting the arm to continuously hit new targets

Imagine if your job was spending all day telling the arm exactly where and when to move. That would be exhausting! If only there were a way to have the arm figure out on its own how to move…

  1. Open scene –> Part 3
  2. Automate yourself out of a job
    1. Open the “Part3RotateArm” script
      • This time we will be writing in the Update() method (because we want the arm to operate continuously)
    2. Use the getHRotation helper function to find the direction the arm needs to rotate
    3. This code will operate in 3 sections. Use if/else if statements to separate them
      1. Add the new angles of movement to the target
        • Don’t be in the middle of a movement
        • Don’t have movements left to execute (hint: “ArmMovementList.Count” will tell you how many movements are in the list)
        • Have a valid (not null) target
      2. Move the arm
        • Don’t be in the middle of a movement
        • Make sure there are still movements left to be executed
      3. Clear the list of instructions (reset)
        • Don’t be in the middle of a movement
        • Make sure there are no more movements left which need to be executed
  1. Profit???
    • Your job is now redundant and can be performed by a machine. Hope your boss doesn’t find out.
  2. BONUS: Implement the getVRotation function so you don’t waste valuable company resources on extra arm movement (efficiency!)
  3. Show your TA your group’s work before leaving lab

Post-Lab (don’t forget to submit your code):

  1. What is the difference between parts 1,2 vs part 3? Why is this difference important? (max 100 words)
  2. Does the arm behaviour in part 3 count as “cognition”? Why or why not? How do you know? (max 100 words)
  3. What was the most difficult part of the lab? Please explain what part exactly was difficult – just saying “the code was hard” is not specific enough.
  4. (Optional) Is there anything which could be improved about this lab?