Games Development / Project 3

 



06.04.2023 - 27.04.2023 (Week 7 - Week 11)
Audrey Gracia Djohari / 0348120
Games Development
Bachelor of Design (Hons) in Creative Media / Taylor’s University
Project 3: Game Prototype


PROJECT 3: GAME PROTOTYPE


Instruction

Students given the task to create the prototype of their game. The prototype doesn’t need to have the final art asset and the use of greyboxing is allowed. The focus here is to quickly test out the game mechanics and to troubleshoot any technical difficulties discovered during the development.

WEEK 10:

Scenes

For this game I have 6 scenes
  • Level 1
  • Level 2
  • Level 3
  • Menu Scene 1 (Shortcut to level 1)
  • Menu Scene 2 (Unlocked after Player finish 2)
  • Menu Scene 3 (Unclocked after Player finish level 3)
Fig 1.0: Scenes in Unity

Level 1 Prototype: The Primate Exhibit

This is the hierarchy of my level 1. It's quite complicated and I used Perspective to arrange my backgrounds, so it took sometime to get the sizes right and to make the set looks good when I try it during Game Play. Below, I will explain the problems I encountered and how I tackled them during the process of making this game.

Fig 1.1: Level 1 Hierarchy

#Obstacle 1: Camera Settings

In prototyping Level 1, the first challenge I encountered was implementing the camera functionality. My vision was to have the camera smoothly follow the monkey's movements while ensuring it stays within the defined boundaries of the level. It took me a long time to figure out how to do this, even ChatGPT couldn't do it with simple scripts.

Determined to find a solution, I sought guidance from Mr. Razif's tutorial video and stumbled upon Cinemachine Camera 2D. This turned out to be a game-changer! I found Youtube tutorial that uses Cinemachine with confiners. Only after using this, I could restrict the camera's movement within the confines I had set around my level. Now, the camera flawlessly tracks the monkey's every move, providing players with an immersive and dynamic gameplay experience without worrying about the camera going beyond the designated borders. 

Fig 1.2: Cinemachine 2D Camera Confiners Tutorial

Fig 1.3: Camera Settings (Cinemachine)

Fig 1.4: Camera Confiner

#Obstacle 2: Perspective & Environment Design

This is my first level so I was not that familiar with Unity 2D. It took me quite a long time arranging the environment using layers. Some helpful tricks that I used:
  • Main Camera < Projection < Choose Perspective
  • I adjusted the Z position of every layers so it has the depth when the character moves around. for example, The platforms's z position is 0, while the trees are 7 so the trees look more far than the platforms.
  • I arranged the layers by using Sprites Renderer < Sorting Layer. I categorize every layers so it has a clear positioning compared to other components.
Fig 1.5: Level 1 Environment


#Obstacle 3: Keys, Doors and Shooting Mode

Next, making the door & keys for Level 1. I used the same way that Mr. Razif taught during class for the door trigger. I made 2 game object, 1 to trigger the opening door animation, and another one to trigger the door closing.

Fig 1.6 & 1.7: Door Trigger Script

For shooting, I want to only enable shooting ability when the player has already collected the trash. So I used this script:

Fig 1.8: Enabling Shooting Ability

In this modified code, the if statement checks both conditions: hasTrash being true and the "Fire1" button being pressed (Input.GetButtonDown("Fire1")). Only if both conditions are satisfied, the code block inside the if statement will be executed.

Fig 1.9: Collectable Trash that enables Shooting


#Obstacle 4: Buttons & Panel Activation (for Game Over, 

I have 3 panels for all levels:
  1. Instruction Panel (activated by a button that always stays at the upper right corner of the screen )
  2. Game Over  Panel (activated when player collides with enemy)
  3. Level Success Panel (activated when player reach the exit touchpoint Game Object)
The idea is to activate Game Over panel when certain situation happens. Overall, these are how I made them possible.
  • I used scripts that is assigned to the button that will activate/deactivate the panels. Then in the button, I made sure to click the + sign in On Click() function and chose the option according to my script. 
  • Learned it the hard way: don't forget to make sure the Canvas UI Scale Mode is set to  "Scale with Screen Size". If it's not set then the panels' size will just be chaotic everytime we adjust the Gameplay screen.
  • Make sure all of the scenes are added in Build Settings.

#Obstacle 5: Enemy (Zookeeper)

I have an enemy with 2D collider. I also have a character. The idea is, when the character touch or collides with the enemy, then a gameover panel will be activated

In this script, the OnCollisionEnter2D function is called when a collision occurs between the enemy and another Collider2D. It checks if the collided object has the "Player" tag using CompareTag("Player"). If the collided object is the character, it activates the assigned panel GameObject by setting it to active using SetActive(true).

Fig 1.10: Enemy Control Script

The enemy also have HP so it will only die when it is hit by 10 bullet trash. I can change the HP in my Unity inspector.

Fig 1.11: Enemy Control Script Inspector

Level 2 Prototype: The Aviary


Fig 2.0: Level 2 Hiearachy
#Obstacle 1: Camera Settings

For Level 2, It has a different camera settings. The idea is to freeze the camera's x and only follows the Player's y movement (upward or downward). So the camera follows the player along the y-axis while maintaining a constant offset. The camera's x and z positions remain unchanged, allowing the player to move freely in the horizontal plane while the camera focuses on the player's vertical movement. The script is straightforward and easy to understand.

Fig 2.1: Level 2 Camera Movement

Here's a brief explanation of the script:
  • public Transform player; : This variable is used to store the reference to the player's transform. It allows the script to know the player's position and follow them.
  • public Vector3 offset; : The offset vector determines how far the camera should stay above the player's position. You can set this value in the Inspector to adjust the camera's vertical position relative to the player.
  • void Update() : This is the update method, called once per frame by Unity.
  • Vector3 position = transform.position; : A temporary variable position is created to store the current position of the camera.
  • position.y = (player.position + offset).y; : The y-component of position is set to the y-component of player.position + offset. This line effectively aligns the camera's vertical position with that of the player, taking the offset into account.
  • transform.position = position; : Finally, the camera's position is updated to the new position value, ensuring that it follows the player with the specified offset on the y-axis.

Fig 2.2: Camera Movement Script (freezing x movement)

#Obstacle 2: Falling Platform Timer

For this level, I want to add something that makes the game more interesting which is making the platform to be fragile and will fall down after a time limit once the player jump on it. When the player touches the ground (falls), then the gameover panel will be activated.

Fig 2.3: Falling Platform Tutorial

FallingPlatform.cs script makes a platform fall after a delay when the player collides with it.  Now let's go through the logic of the script:
  • When the platform collides with any other Collider2D, the OnCollisionEnter2D method is called.
  • Inside OnCollisionEnter2D, the StartCoroutine(Fall()) line is executed. This starts a coroutine called Fall().
  • In the Fall() coroutine, there's a yield return new WaitForSeconds(fallDelay);, which causes the coroutine to pause for fallDelay seconds before continuing.
  • After the pause, the platform's Rigidbody2D is set to RigidbodyType2D.Dynamic, which allows it to be affected by physics and fall.
  • Finally, the Destroy(gameObject, destroyDelay); line destroys the platform game object after destroyDelay seconds, which gives it some time to fall before disappearing.

Fig 2.4: Falling Platform Script

Fig 2.5 & 2.6: Falling Platform Inspector Settings

#Obstacle 3: Egg Spawner

I have birds in my second level that lays egg while moving. 

Fig 2.7: Bird spawning Egg


Fig 2.8: Egg Spawner Game Object

The EggSpawner script is responsible for continuously spawning eggs based on the specified spawnInterval and spawnOffset. Let's break down how this script works:

Fig 2.9: Egg Spawner Script

Fig 2.10: Egg Spawner Tutorial Video

#Obstacle 4: Gameover (Falling Trigger & Character Collision)

Gameover can be caused by 2 things in level 2: Falling and Collision with enemy

This first script is called FallingTrigger, and it is responsible for detecting when the player falls below a certain y-position threshold in the game. Once the player falls below the threshold for a specific duration (fallDuration), the script activates a game over panel (gameOverPanel) in your Unity game.

Fig 2.11: Falling Trigger

Another way that leads to Game Over is when character collides with enemy which is the eggs. This script is called CharacterCollision and is attached to a GameObject representing the character/player. It detects collisions between the character and other objects with 2D colliders (the eggs). In summary, when the character collides with an object tagged as "egg", the script will activate the gameover panel (panelToActivate variable) in the game. 

Fig 2.12: Character Collision (Assigned to Player)

Level 3 Prototype: The City Escape

There aren't much problems encountered in Level 3 because it's pretty much similar to level 1. the difference is it has more enemies (police & zookeepers). This is the hierarchy of Level 3:

Fig 3.0: Level 3 Hiearachy



Menu Prototype

All I did here was assigning scripts to the buttons so it leads to the right scenes. I also added a mouse click sound in the On Click() function by assigning the BG Music Game Object to the function. This is MenuScene1 hierarchy, the other Menu Scenes pretty much have the same hierarchy but more buttons.

Fig 3.1: Menu Hierarchy


Final Prototype

Fig 4.0: Prototype Presentation Video

Drive Link (Scripts): 




REFLECTION

Experience
Creating the first prototype of my game was a challenging and complex endeavor. It required countless trials and errors as I worked to implement the mechanics and design the levels. The process took much longer than expected, with each step presenting its own set of obstacles and frustrations. To navigate through this, I turned to YouTube tutorials to learn the necessary skills and often sought assistance from ChatGPT to help with coding challenges. 

Observation
Throughout the development of the prototype, I observed the importance of patience and perseverance. It became evident that game development is a process of constant iteration and problem-solving. One major issue I encountered was images disappearing during gameplay, only to discover that the image sizes were too large. This led me to learn about the importance of optimizing assets, prompting me to slice and reconfigure backgrounds to prevent them from disappearing when the character moved.
  
Findings
While creating the first prototype, I realized that Unity is an amazing platform for game development. Its powerful tools and user-friendly interface made it possible for me to transform my ideas into a tangible game experience. As I worked on the prototype, I felt like a true programmer, and each step I completed brought a sense of achievement. This experience deepened my passion for game development and inspired me to continue exploring the possibilities of Unity as I progress on my journey.

Comments