Chaos Ball Game
The player will be in an arena. Each of the four corners will have a color, and four balls with corresponding colors will be floating around. Amid the four colored balls, there will be several yellow balls, called chaos balls. Chaos balls exist solely to get in your way and make the game challenging. They are smaller than the four colored balls, but they also move faster.
- The player wins when all four balls are in the correct corners. There is no loss condition.
- Hitting the correct corner causes a ball to become inert.
- All objects in the game are super bouncy. (They lose no momentum on impact.)
- No ball (or player) can leave the arena.
- Ball speeds and chaos ball speeds are randomized.
- Set the resolution of the terrain to 50 by 50. (Remember, this is in the Resolution section of the Terrain Settings.) Add a directional light to the scene. Delete the Main Camera.
- Add a cube to your scene. Place the cube at (0, 1.5, 25) and scale it to (1.5, 3, 51). Notice how it becomes a side wall for the arena. Rename the cube to Wall.
- Create a new folder called Materials under Assets in the Project view. Add a material to the folder (right-click the folder and select Create > Material). Name the material WallMaterial.
- Set the x axis tiling to 10
- Apply the Cliff (Layered Rock) texture to the wall material in the Inspector view.
- Click and drag the wall material onto the wall object in the Scene view.
Super Bouncy Material
- Right-click the Materials folder and select Create > Physic Material. Name the material SuperBouncyMaterial.
- Set the properties for the super bouncy material as they appear in Figure below. Basically, you want everything that reduces energy to be minimized.
- Click and drag the super bouncy material onto the wall object in the scene. It will automatically get applied as the physics material for the collider. You should see the material listed in the Material property of the Box Collider component.
Finish the Arena
Duplicate the wall once. Place the new instance at (50, 1.5, 25).
Duplicate the wall again. Place it at (25, 1.5, 0) with a rotation of (0, 90, 0).
Duplicate the wall created in the previous step (the one that’s turned) and place it at (25, 1.5, 50)..
Go ahead and click and drag a First Person character controller into the scene. Place the controller at (46, 1, 4)
- Add a sphere to the scene. Rename the sphere Chaos and position it at (15, 2, 25) with a scale of (.5, .5, .5).
- Click and drag the super bouncy material onto the sphere.
- Create a new material (not a physics material) for the chaos ball called ChaosBallMaterial. In the color selector for the material, select a bright yellow color. Click and drag the material onto the sphere.
- Add a rigidbody to the sphere. Change the angular drag to 0 and uncheck Use Gravity. Change the Collision Detection property to Continuous. Under the Constraints property, freeze the y position. We don’t want the balls to be able to go up or down
- Open the Tag Manager (click Edit > Project Settings > Tags), expand the Tags section by clicking the arrow next to Tags, and add the tag Chaos at Element 0. While you’re here, go ahead and add the tags Green, Orange, Red, and Blue. These are used later.
- Select the chaos sphere and change its tag to be Chaos in the Inspector view
- You need to create a script to move the ball all around the arena. You need to create a script called VelocityScript and attach it to the chaos ball
The Colored Balls
- Add a sphere to the scene. Rename the sphere Blue. Position the sphere somewhere near the middle of the arena, and make sure that the y position is 2.
- Create a new material called BlueMaterial and set its color to blue the same way you did for the chaos balls. While you’re at it, go ahead and create RedMaterial, GreenMaterial, and OrangeMaterial and set them to the appropriate color. Click and drag the BlueMaterial onto the sphere
- Click and drag the super bouncy material onto the ball.
- Add a rigidbody to the sphere. Change its angular drag to 0, uncheck Use Gravity, and freeze the y position under Constraints.
- Previously, you created the Blue tag. Now, change the sphere’s tag to Blue just like you did for the chaos ball
- Attach the velocity script to the sphere. In the Inspector, locate VelocityScript (Script) component and change the Max property to 25. This causes the sphere to move slower than the chaos balls initially.
- Duplicate the blue ball. Rename the new ball to its color: Red, Orange, and Green.
- Give the new ball the tag corresponding to its name. It is important for the name and the tag to be the same thing.
- Drag the appropriate color material onto the new ball. It is important for the ball to be the same color as its name.
- Give the ball a random location and rotation in the arena, but ensure that its y position is 2.
Each of the four corners has a specific colored goal that corresponds with a colored ball. The idea behind the goal is that when a ball enters, the goal will check its tag. If the tag matches the color of the goal, there is a match. When a match is found, the ball is set to Kinematic (remember that makes it inert) and the goal is set to Solved
- Create an empty game object (click GameObject > Create Empty). Rename the game object BlueGoal and assign the tag Blue to it. Position the game object at (1.6, 2, 1.6).
- Attach a box collider to the goal and check the Is Trigger property. Change the size of the box collider to be (1.5, 1.5, 1.5).
- Attach a light to the goal (click Component > Rendering > Light). Make it a point light and make it the corresponding color of the goal). Change the intensity of the light to 3.
- create a script called GoalScript and attach it to the blue goal
- Duplicate the BlueGoal. Name the new goal corresponding to its color: RedGoal, GreenGoal, and OrangeGoal.
- Change the tag of the goal to its corresponding color.
- Change the color of the point light to the goal’s corresponding color.
- Position the goal. The colors can go in any corner as long as each goal gets its own corner. The three other corner positions are (1.6, 2, 48.4), (48.4, 2, 1.6), and (48.4, 2, 48.4).
The Game Controller
The last element needed to finish the game is the game controller. This controller will be responsible for checking each goal every frame and determining when all four are solved.
- Add an empty game object to the scene. Move it someplace out of the way. Rename it GameController.
- Create a script called GameControlScript. Attach the script to the game controller.
- With the game controller selected, click and drag each goal to their corresponding property on the Game Control Script component