Beginner Tutorial


Physics Part 2


15 minutes

Posted on: October 13, 2017

Learn Sumerian
Physics Part 2

Tags

pinball
physics
rigid body
collider

In this tutorial you will learn about:

Rigid body
collider
translation
hierarchy

In Physics Part 1, we started building a pinball game by using Amazon Sumerian physics. When we pressed play, the ball moved around and eventually fell off the pinball Table in a physically realistic way.

In Part 2, we’ll enhance the scene by adding controls and Flippers using a custom script to create a functional game.

You’ll learn about:

  • Rigid Body component
  • Collider component
  • State Machine
  • Scripting

Prerequisites

Before you begin, you should have completed the following tasks and tutorials:

Step 1: Reset the Table Tilt

We’ll add two more Bumpers, the bottom Flippers, and Slants. Then we’ll use a script to create the appropriate behavior. But before we can add new entities to the Table, we have to reset the Table tilt.

The Table’s X Rotation is currently set to 36. Reset it to 0. To see these values, select the Table in the Entities panel, and expand the Transform component in the Inspector panel.

Step 2: Add Two More Bumpers

There are currently three Bumpers and we want to add two more.

  1. Duplicate Bumper1 two more times (using the Duplicate button at the top of the Entities panel) to create Bumper4 and Bumper5.

  2. With the new Bumpers selected, use the Translation gizmo to move them. Be sure you have the Translation gizmo selected in the upper right of the canvas.

  3. Drag the new Bumpers to different locations on the Table. However, don’t change the Y Translation, because this will lift the Bumpers off the table.

Step 3: Add Slants

Now we add the Slants. These are at the sides of the Flippers and keep the ball from falling out the bottom.

  1. From the Create Entity menu, add two more Boxes, and then rename them “LeftSlant” and “RightSlant”.

  2. Change the Transform values for the LeftSlant and RightSlant to the following.

  3. Add a Collider component to both LeftSlant and RightSlant with the following settings.

    Your table should look something like this.

Step 4: Add Flippers

Flipper Pivots

The Flippers need to hinge on one side. To get this effect, we need to provide an anchor so the entities will hinge instead of spin. We use an Empty parent entity as the anchor.

  1. Add two Empty entities from the Create Entity menu.

  2. Rename the empty entities “LeftFlipperPivot” and “RightFlipperPivot”.

  3. Change the Transform values of the LeftFlipperPivot to the following: Translation (-7.825, 1.5, 13.5) and Rotation (0, -23, 0).

  4. Change the Transform values of the RightFlipperPivot to the following: Translation (7.825, 1.5, 13.5) and Rotation (0, 23, 0).

  5. Give them each a Rigid Body component and check the Kinematic checkbox.

Flippers

  1. To add the Flippers themselves, add another two Boxes. Name them “LeftFlipper” and “RightFlipper”.

  2. In the Entities panel, nest the left and right Flippers under their respective Pivot entity by dragging and dropping the Flippers onto the Pivot entities.

  3. Nest the both the LeftFlipperPivot and RightFlipperPivot entities under the Table entity by dragging-and-dropping them onto the Table entity. Here is the final entity hierarchy in the Entities panel.

  4. Change the LeftFlipper Transform values to the following: Translation (3.5, 0, 0.5) and Scale (7, 2, 1).