Skip to content
Cawd Logo GAWD
  • Home
  • About
  • Assignments
  • Resources
  • Contact

Friday, April 12th

Friday, April 12th

Class hours: 10:05 – 2:45
Mr. Bohmann | wbohmann@ewsd.org

10:05 Today’s Notes & Attendance

Week 30 – quick and short week

Happy 18th Birthday – Finn!

One week to vacation – we are now moving primarily to game with some animation

WorkKeys make-up test: John St. Pierre – Report to room E109. This is past the Auto Dept. PreTech 1 classroom.

Career/Hiring Fair for Transportation, Logistics and Public Safety from 11:30-2:00 in the library. You may go at 1pm if you are interested.

PSA Registration Link – Click for the cash! Use Center for Technology – Essex as your school


10:10 Unity – Pinball

Before Skills we used the Unity physics engine to create realistic collisions between objects.

Collisions are an important part of gameplay. If the player shoots a target, your game might update a score, or if the player hits an obstacle, he or she might lose some health, or if there is a goal or a basket, the player should be rewarded! This game logic requires more than just the physics engine – you also need to write some scripts.

Besides collisions, there are other event driven programming:

  • Player clicks on a button
  • Timer countdown reaches zero
  • Player health reaches zero
  • Player wins the game
  • …and of course, a collision between objects!

OnCollisionEnter2D

As soon as you add a Collider 2D component to your game object, Unity can run a specific function every time a collision occurs with that object.  OnCollisionEnter2D() function can be added to your script.

When a function is called, it is possible to give that function some useful data. The function can then use that data to perform a task. The data is listed inside the function parentheses right after the function name.

For our example, (Collision2D otherObject) is the parameter. The first part (“Collision2D”) shows the type of data and the second part (“otherObject”) is the local name for that piece of data that we can use inside our function. Of course we could use the name “pizza” as our local name, but that doesn’t make much sense.

Once you add the OnCollisionEnter2D() function to your script and attach that script to a game object with a collider, the function will be called each time a new collision is detected with another object that also has a collider.

void OnCollisionEnter2D(Collision2D otherObject)
{
     // Code here runs when collision occurs
     Debug.Log("Collision with: " + otherObject.gameObject.name);
}

OnTriggerEnter2D

So far, all of our collisions have resulted in some real-world reaction from the objects that hit each other. Beach balls bounce and bowling pins go flying. However, you may want to detect collisions in cases where there should be no real-world physics reaction. Like when a ball crosses the goal line in soccer or your car jumps or crosses over a powerup. In those case you want to trigger an event.

With “Is Trigger” checked, your collider will detect collisions but game objects will not be part of the game physics when a collision happens. You will get an event-driven function call that you can use to run game logic, but the two objects will pass through each other on the screen.

void OnTriggerEnter2D(Collider2D otherObject)
{
     // Code here runs when a trigger collision occurs
     Debug.Log("Trigger with: " + otherObject.gameObject.name);
}


Pinball is a classic stand-up arcade game and one that I played a lot growing up. A steel ball is shot onto a playing surface and bounces between bumpers and other gadgets, scoring points. The player tries to keep the ball in play with flippers or paddles at the bottom. Making a Pinball game is a great chance to show off the physics engine in Unity and some of the skills you worked on the last few days with movement. Open the project we created called 2D Playground (or something like that)

Create a New 2D scene (called) PinBall

Project Details

For our game, a ball will drop from the top of the screen to start the game. As it falls, it will bounce off a series of bumpers on the screen. The player will move a paddle to the left and right at the bottom of the screen to prevent the ball from falling down the “hole” at the bottom of the screen. Once the ball falls down the hole, the game is over.

The boundaries of the game are a series of rectangles with box colliders added.

A prototype – is not a final version but great for testing!

You will add the rigidbody, collider, and physics material components to the ball, bumpers, and paddle to make the game work correctly! You will also write the C# script to control the paddle movement and detect when the game is over.

Let’s create a simple prototype. Later we an add our own look to customize our game. Let’s just get the mechanics working. A minimum viable product is what we are after. For reference, I’ve created my own basic prototype above. You can copy or create your own.

You will need:

  1. A Movement Script for your player so that when you use the A or D key, your paddle moves around
  2. A Ball Script for detecting game over (We’ll code together)
  3. Add RigidBody 2D to your pinball
  4. Use physics materials (that you create) to manage your bumpers
  5. PlayTest your game
  6. Challenge: Can you respawn your ball if you lose?


10:50 Break

11:00 Unity Continued….

11:45 Vermont Highway Safety Alliance Showcase

Let’s celebrate by watching your video. You don’t have to do anything except press play. We’ll watch each video twice. If you want to share something you are proud of, we’d love to hear it.

Dropbox for your YouTube Link

12:25 – 12:55 Lunch

tacos

12:55 Independent Reading

book covers

1:20 Break

1:30 20% Project Time

Google 20% graphic

2:40 Dailies

Dailies can be placed in the CAWD2 Dailies Folder on the CAWD2 Public Folders drive

2:45 Dismissal

GAWD Instructors:

Matt Cronin

Will Bohmann

Instragram Facebook Twitter

A little about GAWD:

Serving high school students interested in Gaming, Animation, and Web Development in North Western Vermont.

Students continue at:

University of Vermont Ringling School of Art and Design Northeastern University Rochester Institute of Technology Concordia University

Students find careers at:

Dealer.com Union Street Media Rovers North Prudential Investments DockYard
Navigate to top of page