Platform Boy

Platform Boy

The final project for us to create was a platformer style game. For this project I did not have a set story in mind, or what I wanted the game to look like. Instead, my goal was to explore animation and get to know the basics of animating a character, whilst also having enemies patrol platforms.

Exploration

Similar to the other projects, I first followed the tutorial provided for us, to know how to set the scene up, in order for me to start experimenting with the animation and enemies. I then went on and created a simple level layout for the character, and included places where the player could die and places where the player would be able to collect keys to win the game. The sprites used in this project were downloaded for free from – https://kenney.nl/assets/simplified-platformer-pack. After this, I then used my knowledge from previous projects and included sound, the game over, restart and win mechanics and also background music into the project. Next I placed the enemies into suitable patrol positions. However, after doing so this is when I encountered my first problem.

Platform Boy Interface

Challenges

Having the enemies patrol on the platform was what I intended for this project. However, this process was found to be very problematic. Firstly, I needed a script which controlled the enemy movement. I had researched this and found a script which I desired. The problem was that the enemies would flip back and forth rapidly on their platform, and this was due to the colliders constantly flipping the characters. I had spent two hours finding a solution for this problem, and the problem was that the enemies required to have two separate colliders. A 2D Box Collider for their body which controlled when they would move in the opposite direction, and a 2D Capsule Collider for their feet which controlled their movement. These colliders could not overlap, as this overlap would cause the bug to occur. After fixing the collider issue the enemies then patrolled their platforms as intended. This was the most frustrating problem I have encountered so far.

Enemy Collider Bug

Another problem I encountered was the sound triggers. I had created sound which I wanted to trigger when the player collided with an enemy and when the player collided with a Key. I encountered a similar problem in the Alien Invasion project, where I wanted a sound to play whenever a enemy was destroyed. However, after experimenting with the engine, I had discovered that the Audio Source must be attached to the object which is still in the scene after the sound is triggered. For example, the sound when the player would collide with a key was a ding, which indicated that the player was progressing through the game. The Audio Source must be attached to the player instead of the key, as the key no longer existed in the scene after the player had collided with the key. With Unity showing an console error and not triggering the sound.

In this project, the script I found most difficult was the AI Patrol script. This script consisted of multiple functions, such as Flip, Patrol and an OnTriggerEnter2D function. The functions all work together to control the enemy to patrol the platform they have been placed on, and detect if they have reached the end of their platform. If they have reached the end of their platform then the enemy will move in the opposite direction. Since this was my first experience of an enemy patrol script, I was slightly confused at first. Nevertheless, after looking at the lines of code and analysing each function I then understood what each line outputs. Which, similar to other scripts I have created, will give me experience in future projects.

AI Patrol Script

Unity Strengths and Weaknesses

With this project, I had found that Unity’s features do not work as intended, and I believe these to be a weakness of the system. For example, the 2D Box Colliders placed onto objects which moved are very problematic. Often when a player or enemy is moving they would become stuck on a flat surface. To fix this, the 2D Box Colliders would need to be replaced with 2D Capsule Colliders which ensure the objects are moving smoothly across the surface.

Another weakness that I believe Unity holds is the triggering of sounds on collision. As mentioned above, the Audio Sources need to be attached to the object which still exists in the scene after the sound has been triggered. I believe this to be a weakness as the engine should be able to play the sounds after the object has disappeared in the scene. As I had to fix this problem by attaching multiple Audio Sources to the player. Additionally, I encountered this problem in my Alien Invasion project.

One definite strength of the engine is that it gives the user the ability to use Vector Snapping for quick creation and placement of tiles in a level. The user can select an object and hold ‘V’ to move the object and quickly snap it to another object, which accelerates the level design stage.

Additional Research

The additional research I undertook for this project was to find out how to animate a character, and to also find out how to create an enemy patrol script. These videos explained how to create the animation and patrol system easily (Blackthornprod, 2019; Scriven, 2020).

References

Blackthornprod (2019) MAKING RUN, IDLE & JUMP 2D GAME ANIMATIONS – UNITY TUTORIAL [Video]. Available online: https://www.youtube.com/watch?v=FTxQKHG5WCA&ab_channel=Blackthornprod [Accessed 9/11/2021].

Scriven, M. (2020) 2D enemy PATROL AI in Unity – Part 1 [Video]. Available online: https://www.youtube.com/watch?v=rn3tCuGM688&ab_channel=MikeScriven [Accessed 9/11/2021].

Please click the link to play Platform Boy – https://nathan1230.itch.io/platform-boy