Chaos Ball Game

The Concept

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 Rules

The Arena

  1. 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.
  2. 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.

Texturing

  1. 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.
  2. Set the x axis tiling to 10
  3. Apply the Cliff (Layered Rock) texture to the wall material in the Inspector view.
  4. Click and drag the wall material onto the wall object in the Scene view.

Super Bouncy Material

  1. Right-click the Materials folder and select Create > Physic Material. Name the material SuperBouncyMaterial.
  2. Set the properties for the super bouncy material as they appear in Figure below. Basically, you want everything that reduces energy to be minimized.
  3. 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)..
  • The Player

    Go ahead and click and drag a First Person character controller into the scene. Place the controller at (46, 1, 4)

    Chaos Balls

    1. Add a sphere to the scene. Rename the sphere Chaos and position it at (15, 2, 25) with a scale of (.5, .5, .5).
    2. Click and drag the super bouncy material onto the sphere.
    3. 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.
    4. 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
    5. 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.
    6. Select the chaos sphere and change its tag to be Chaos in the Inspector view
    7. 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

    1. 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.
    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
    3. Click and drag the super bouncy material onto the ball.
    4. Add a rigidbody to the sphere. Change its angular drag to 0, uncheck Use Gravity, and freeze the y position under Constraints.
    5. Previously, you created the Blue tag. Now, change the sphere’s tag to Blue just like you did for the chaos ball
    6. 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.
    1. Duplicate the blue ball. Rename the new ball to its color: Red, Orange, and Green.
    2. Give the new ball the tag corresponding to its name. It is important for the name and the tag to be the same thing.
    3. Drag the appropriate color material onto the new ball. It is important for the ball to be the same color as its name.
    4. Give the ball a random location and rotation in the arena, but ensure that its y position is 2.

    The Goals

    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

    1. 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).
    2. 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).
    3. 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.
    4. create a script called GoalScript and attach it to the blue goal

    5. Duplicate the BlueGoal. Name the new goal corresponding to its color: RedGoal, GreenGoal, and OrangeGoal.
    6. Change the tag of the goal to its corresponding color.
    7. Change the color of the point light to the goal’s corresponding color.
    8. 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.

    1. Add an empty game object to the scene. Move it someplace out of the way. Rename it GameController.
    2. Create a script called GameControlScript. Attach the script to the game controller.
    3. With the game controller selected, click and drag each goal to their corresponding property on the Game Control Script component