Bounce, bounce, bounce, bounce

Grab the repo first! There is starter project/code in there.

https://classroom.github.com/a/Xy8dNQNj

Part 1: Boing!

Get the orange circle bouncing off one wall.

Start here: introduction to wall collision

Previous in-class video, some slight differences in project setup. Login to Blackboard in order for videos to show.

Directions

  1. Update the Bounce.cs script on the circle to make it move at constant velocity (just like in lab01, but without user control)
    • In Start, set the _velocity vector to some hardcoded random direction
  2. Make it bounce off whichever wall it's headed towards
    • Pre-calculate the size of the "world" and the size of the circle
      • Use Camera.main.ViewportToWorldPoint, and note that the viewport goes from 0,0 to 1,1
      • Use GetComponent and SpriteRenderer.sprite.bounds.extents to determine sprite size
    • Using those values, check for collision with the wall in Update
    • Respond to collisions by (1) moving the entity out of the wall and (2) changing the velocity as discussed in the video above.

Part 2: I'm the man in the box

Complete the collision detection and response for all four walls.

Directions

  1. Update the starting velocity to a random (instead of hardcoded) direction
    • Use Unity's built-in Random.Range method
    • Set random x,y values and normalize (or use unity's built-in functions to rotate a unit vector a random angle)
    • Set _velocity to that random direction vector multiplied by SPEED
  2. Repeat the wall collision code from part one four times (one for each wall)

Part 3: A little help from my friends

Add two more circles to the scene and use the same script on all three. You shouldn't have to make any changes to the script to have it work on the three separate circles which should each start off in their own random direction.

Part 4: Ninja!

Too predictable. Make the three circles appear at different times.

Start here: introduction to spawning

Previous in-class video, some slight differences in project setup. Login to Blackboard in order for videos to show.

Directions

  1. Parent the circles to the CirclePool empty entity outside the camera view
  2. Disable the Bounce.cs script on each circle so they don't start updating
  3. Attach the Spawner.cs script to the CirclePool
  4. Finish the script so that it "spawns" a circle every 3 seconds:
    • In Update (so it runs every frame)...
    • Keep track of total time passed since the "game" started
    • If you have children left...
    • And another three seconds has passed...
    • Unparent the first child, move it into the camera view, and activate it's movement script

Hint videos, working with a different example