In this two-part tutorial series, we’ll build a pinball game using Amazon Sumerian physics. In Part 1, you create a table that’s tilted on an angle, a few cylinders, and a ball and you will be introduced to the Rigid Body and Collider components. In Part 2, you enhance the scene using physics to create a simple pinball game.
This is the scene we will build in this tutorial. Use the left and right arrow keys to control the pin ball machine. For best results, use the latest version of your browser..
In this part, you’ll learn about:
- Rigid Body component
- Collider component
- Translation component
- Entities panel
Before you begin, you should have completed the following tasks and tutorials:
- Sign in to Amazon Sumerian with your AWS account
- Amazon Sumerian Interface tutorial
- Sumerian Basics: Creating a TV Room
- Scripting Basics tutorial
- Material Fundamentals tutorial
- Nesting Using a Solar System tutorial
The primary components that produce physics within Sumerian are the Rigid Body component and the Collider component.
The Rigid Body component is mainly responsible for tracking the position, Rotation, and Linear and Angular velocity of a physical object. This component carries many properties, but at its core, a Rigid Body component adds gravitational pull to an entity.
The Collider component is responsible for calculating and detecting collisions between physical objects. It tells the Amazon Sumerian engine to treat an entity as a physical object. Otherwise, objects would just pass through one another.
A Rigid Body component can also act as a trigger, or a motion sensor. Other physical objects passing through a Rigid Body component trigger a responsive action.
Together, these components make it possible to create physical behaviors.
A Few Use Cases
1. I want to create a fixed, physical object.
Use a basic shape (box, sphere, cylinder, quad) and add a Collider component. Then select the correct shape in the Collider settings. Alternatively, you can add a Rigid Body component and set the mass to zero.
2. I want to create a dynamic physical object that’s affected by gravity and collides with other physical objects.
Select the correct shape in the Collider settings, and set the mass setting in the Rigid Body component to something that matches the weight (in kilos) of the object you are creating.
3. I want to create a physical object and use a Sumerian script to control the linear and angular velocities.
Use a basic shape and add a Collider component and a Rigid Body component. Select the correct shape in the Collider settings and set the kinematic setting in the Rigid Body component. Then see part 2 of this tutorial to learn how you can set the velocities.
Step 1: Set up the Scene
From the Dashboard, create a new scene using the Default Lighting template. This scene will come with a camera, a light, and a skysphere (i.e., the blue sky).
Step 2: Build the Table
We’ll create a box, a few cylinders, and a ball and give them physical attributes. Then we’ll tilt them all as a group to initiate the actions.
Create the Parent Entity
Open the Create Entity menu, choose the Empty entity, and then name it “Table”. This will be the parent to group all the pieces of our pinball table.
Create the Floor
Add a Box entity to the scene. Rename the Box entity to “Floor”. Change the new Floor entity’s Scale to (20, 1, 40).
Add a Collider component to the Box by choosing Add Component in the Inspector panel.
In the Collider component, change the Friction and Restitution to 0.
Friction is the resistance that one surface or object encounters when moving over another. In other words, how “slick” is it? Restitution is best described as “bounciness”. We set both to zero because we don’t want the ball to bounce on the pinball floor but we also don’t want Friction to slow it down.
Add the Walls
- Create another Box and change the name to “LeftWall”. Then give it the following Transform values.
- Translation: (-9.5, 1.5, 0)
- Scale: (1, 2, 40)
Add a Collider component, and then set Friction to 0 and Restitution to 0.5, so that the Ball bounces off the wall.
Duplicate the LeftWall (by choosing the Duplicate button at the top of the Entities panel), and rename the duplicate to “RightWall”. Change X Translation to 9.5.
- Add the TopWall by duplicating one of your current walls. Rename it “TopWall”, and then change the transform values, as follows.
- Translation: (0, 1.5, -19.5)
- Scale: (20, 2, 1)
Your scene should now look like this.
- Finally, we need to nest all our entities into a parent entity. For this we’ll nest the Floor and Walls under the empty Table entity we created at the beginning. To nest entities, drag and drop them into the parent entity, in our case, Table. Your Entities panel hierarchy should look like this.
Step 3: Rotate and Add a Ball
Now that we have the correct hierarchy, we can move all the Table entities together, as if they were attached.
Select the Table parent entity, and change the X Rotation to 36. Your Table should be tilted like this.