Click here to Skip to main content
15,885,216 members
Articles / Game Development / Unity

Exploring Electronic Game Development 2D Supported by Unity Engine

, ,
Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
17 Nov 2022Apache12 min read 5K   8   2
Unity Engine support for Electronic 2D game development
This work proposes to explore the Unity game engine that currently has a worldwide prominence in the digital game creation market, with the objective of experience the development of a 2D platform game by contributing with a practical analysis of the benefits and report the difficulties of this process.

1. Introduction

Motivated by the great growth of the gamer community in Brazil and in the world, the search for increasingly productive game development tools and low-cost engines has opened up a wide variety of options among the development of current games.

Based on this scenario, this article is part of a series of articles (Macario, Silva and Silva, 2022) that promote the validation of techniques and practices as facilitating mechanisms in the development of electronic games. All projects have a practical character, always maintaining the didactic, experimentation character and always trying to contribute to the community of computer science and game production.

2. Background

There are several options of tools to support the game development process, both considering GPL (GNU General Public License) solutions and products with paid licenses. However, these tools are not always easy to use. Often making it difficult to understand simple events within the context of game development and when this does not occur, the support tool imposes restrictions to distribute the final product game.

Analyzing current engines on the market, Unity stands out for having an organized interface that helps in the manipulation of scene objects, a large library of graphic functions and many animation resources that greatly facilitate the game development process and its distribution to the vast majority of current platforms. In addition, Unity is available for free to anyone starting out in the world of digital game development, as long as your annual revenue does not exceed $100,000 and its use is free.

This work has as its theme the development of a 2D game (two dimensions) of the platform genre using the Unity tool and its facilities, through a synthesized approach to game design, character creation, animation and programming in C# language. Using a linear development method, divided into steps to solve problems and use resources, also making use of manual drawing tools and graphic editing software.

3. Proposal and Technical Project

The proposed prototype presents as a scenario the construction of a complete game, with characters, beginning, objective, interactions, actions, cycle of states and rewards. This is to provide a basis for the expected validations in this research, which is to contribute with a practical review of the use of a tool as a facilitator in the construction of a complete game with 2D characteristics. On the other hand, the extra features, for example, score control, continuity, history, and user integration, will be left out as they are not directly related to the basic game development tool.

For the development of the game, the programming language C# is used for the creation of input controls, collision, animation state transition, control physics, as well as the variation control between phases and start and end game menus (Figure 1).

The tools used for the construction of this project were:

  • Unity Engine 2021: Game development engine used in this project.
  • Visual Studio Code: Used in conjunction with Unity for development of scripts (instructions) in C# language.
  • Adobe Photoshop 2021: Image editor for creating and manipulating the visual elements of the game.
  • GitHub: System for version control of coding in C# language.
  • Diagrams.net: multiplatform system used in the production of the flowchart introduced.

In the initial phase of development, a study was carried out to deepen the knowledge of existing features in Unity using documentation and tutorials provided by Unity Technologies itself, as well as all material made available by your community at large. At this stage, it was possible to notice how much robust and friendly is the Unity game engine with which it is possible to develop games with few external tools, yet a reasonable understanding of programming, editing and animation production.

Figure 1 shows the flowchart that basically represents the functioning of the game structure involving the possible actions of the character that are expected to be performed for the completion of the proposed game.

Image 1

Figure 1. Basic operation flowchart of the game

When starting the creation of the proposed game with Unity, it was necessary to understand some basic aspects of how it works internally. It has a structure that should be considered when creating a game with the tool. It is necessary to understand and how to work with game objects. Every game in Unity is scene-based, and game objects are all elements within a scene. When entering the scene, these elements receive 3D coordinates (three dimensions) and all scene elements can be moved using these coordinates in the Transform class of each game object; this class is responsible for controlling the positioning, rotation and scale of every element in the scene. Just like the Transform class, a Sprite Renderer (class responsible for controlling the image aspects of each 2D element) is also applied to every object that enters the scene. These classes interact with the element in the scene through inheritance from the Component class, which in turn interact with the GameObject class, which inherits from the Object class and are implemented from the UnityEngine library of the graphics engine, this library is defined automatically in the generated scripts by the Unity platform for any code that interacts with the graphics engine.

The possibilities of integration with the game for the user of the system is, in addition to starting the game (START) is basically the manipulation of the main character, Rocni, according to her possible interactions with the world defined and controlled by the game script (Figure 2).

Image 2

Figure 2. Basic interaction from Rocni character

Figure 2 represents, through a use case diagram, the possible interactions of the protagonist character, through the commands available to the player user, with the world. In this case, from two screen components, in fact, two control buttons, arcade style, the player can: instruct the character Rocni to run, jump, interact with objects (collection) or attack enemies.

Also consider graphic elements, the main character Rocni is represented by frames (Figure 3) of a small ninja in different positions, which are animated when displayed at a certain frequency per second, thus creating the animation of each state of the character, this frequency varies according to the speed of each action performed, some of these frames can be seen in figure 3.

Image 3

Figure 3. Possible pictures shot of the main character Rocni

The flow control of the character's animations is done through the Animator component, which constitutes the relationship between the animations and the scene events through parameters defined in the script, this flow can be seen in Figure 4. This figure, 4, presents the set of possible states and their transition rules.

To manage the character's interactions with the game universe and then control the set and rule of its states, the project relied on an engine based on an algorithm fully developed in C# but which can still be manipulated within the Unity implementation console. This environment also allowed debugging and testing to be performed in a highly integrated manner.

Image 4 Image 5
Figure 4. Set and rules to Rocni state machine

Semantically, both diagrams represent the same state lifecycle. While the first is focused on discussions and specifications during the definition of the game project, the second is automatically extracted from the reading of one of Unity's reengineering components carried out on the script itself developed to control the state flow of the game's characters .

For the input controls, collision checking and wirelining of the character's physics relationship and its animations, C# scripts were written from which it is possible to verify the libraries used as well as part of its variables and objects, of which the Unity library is the largest responsible for all physics applied in the game environment.

4. Using the Code

For the construction of the scene elements, the arts available free of charge on the website gameart2D (2022) were used. These arts, when introduced into the game, are converted into game objects and comprise all objects that can be viewed by the player during the game.

In figure 5. The game's start menu is running on the Android platform console, and it is possible to notice a wide variety of elements that compose it, from its activation buttons to the main character and his enemy, as well as the objects of scene and background.

Image 6

Figure 5. First screen and start menu option

It is possible to identify the simplicity of the prototype that purposely concentrated the development activity on the construction of game elements and interactions and not on handling and administration operations.

In Figure 6, the game has started and it is possible to make some decisions, for the character Rocni to reach his objective which is to reach the school of ninjas, he must jump on the platforms, collect the coins on his way and avoid or eliminate the "dinos " enemy that arise, if the character is caught by a "dino" or fails to jump through the platforms and falls into the river, he dies returning to the starting point and having the count of his coins reset, after a practical test, it was possible to complete the scenario without major difficulties.

Image 7
Image 8
Image 9
Figure 6. Execution test: (a) Rocni starting the journey, (b) interacting and (c) jumping

In addition to the main character and his interaction possibilities, it is also possible to identify through Figure 6 several elements relevant to more traditional game scenarios, such as:

  • orientations: trail; starting point; and conclusion point;
  • interactions: enemies; fixed blocks, floating blocks; fixed objects for collection; and mobile objects for collection;
  • context: scenery objects; scenery background; start limits; and finish limit;
  • commands: the arcade control components; pause and stop option.

Both these elements and the scenario transitions (horizontal and vertical) were entirely built, manipulated and tested with the support of Unity without any other source of technical resource needing to be explored (Code 1). By the way, the only activities developed outside the Unity development environment were capturing images and styles libraries, necessary to speed up and skip element building steps since they were not within the scope of analysis of this project.

Code 1. Snippet source code to present the import modules

C#
//import modules, base to execute the core game

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System;

4.1. Drawbacks

During the initial tests, it was possible to notice that when executing some animation transitions, they occurred asynchronously as defined by the parameters stipulated in the Animator component, after some changes and tests verifying the triggers of each event; it was found that they were occurring correctly, which led to checking the transitions created more carefully, as the Unity platform was first developed for the development of 3D games, animations could not be executed instantly for this reason there are fields has exited time, transition duration, and transition offset are set by default to make transitions more natural state in a 3D animation. However, when working with 2D animation, these settings cause asynchrony of the animation states, as reported, to solve the reported problem, it was necessary to uncheck the exit time field and reset the transition fields.

Another problem found was that at first the game would be built only for Windows, but with development, it became interesting to adapt it to Android as well, in view of its portability and popularity, but the input controls that comprise both keyboard and keyboard inputs of gamepads now needed to be able to capture input from touchscreens. After several changes in the input instructions that caused unexpected behavior such as delay or even launching the character out of the space defined in the scene; the Input System component was added to the project, this Unity component adds, in a very practical way, input functionalities for several platforms, but until now it is not installed by default with the game engine, being necessary to install its package separately in Window> Package Manager > Input System and clicking Install. With its addition to input controls, it is possible to build the game for both Windows and Android and make use of both gamepads, keyboards and touch screens, which is a considerable increase in the availability of inputs.

5. Conclusion

The final prototype has basic elements of a digital game, maintaining a nostalgic relationship with platform games that were released in the mid-1990s, classics like Super Mario, Sonic, Bionic Commando, among others. Despite being considered completed, this product is not able to enter the electronic games market and compete with other titles. This would require more time and resources, with the addition of more stages, addition of minigames, inclusion of more items, power ups (items that increase skills), inclusion of internal microtransaction system and perhaps an online multiplayer system. With the end of this project, it can be seen that no matter how complete the tool for developing digital games is, the development process is still quite challenging due to the accumulation of skills that are necessary to carry out a minimally satisfactory project; it was clear the link between programmer, graphic designer and animator in this type of project and why digital games are usually developed by teams and depending on the game these teams can have more than 200 collaborators.

Source Code Repository

References

  1. Unity (2022). “Site Oficial do Unity” [online]. Available at https://unity.com/pt. Accessed in 2022.
  2. Unity (2022.b). “Tutoriais” [online]. Available at https://unity3d.com/pt/learn/tutorials. Accessed in 2022.
  3. Documentação Unity (2022.a). “Introdução as funções do Unity” [online]. Available at https://docs.unity3d.com/Manual/index.html. Accessed in 2022.
  4. Documentação Unity (2022.b). “Conceitos de scripts” [online]. Available at https://docs.unity3d.com/Manual/ScriptingConcepts.html. Accessed in 2022.
  5. Documentação Unity (2022.c). “Desenvolvimento 2D” [online]. Available at https://docs.unity3d.com/Manual/Unity2D.html. Accessed in 2022.
  6. Visual Studio Code (2022). “Site Oficial do Visual Studio Code” [online]. Available at https://code.visualstudio.com/docs. Accessed in 2022.
  7. ClaudioSP (2022). “Código fonte do projeto disposto no GitHub” [online]. Available at https://github.com/ClaudioSP/Unity_Project2D_01/tree/master. Accessed in 2022.
  8. Gameart2d (2022). “Ativos de arte livres de Royalties para jogos 2D” [online]. Available at https://www.gameart2d.com. Accessed in 2022.
  9. Bensound (2022). “Músicas livres de Royalties para produções em geral” [online]. Available at https://www.bensound.com/royalty-free-music. Accessed in 2022.
  10. Microsoft (2022). “Guia de linguagem C-sharp da Microsoft” [online]. Available at https://docs.microsoft.com/pt-br/dotnet/csharp.. Accessed in 2022.
  11. Macario, V., Silva, A. M. e Silva, J. C., (2022). “Development of a Raycast Engine based on Javascript Technology” Codeproject, for those who code! Technical Report Publication Plataform [online]. Available at https://www.codeproject.com/Articles/5347118/Development-of-a-JavaScript-Based-Raycast-Engine. Accessed in 2022.

History

  • 10th November, 2022 - Document creation
  • 13th November, 2022 - Textual revision
  • 16th November, 2022 - Revision and validation
  • 17th November, 2022 - Document submit

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Business Analyst
Brazil Brazil
agile and devops enthusiast; master in computer science and professor in  technology courses; I have worked with projects and development for the telecommunication area
This is a Collaborative Group

5 members

Written By
Software Developer
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Collaborative Group

1 members

Written By
Student
Brazil Brazil
Hello, I'm Victor, a Computer Science student, I'm very interested in front end and back end.

Comments and Discussions

 
SuggestionFigure 1 Pin
Сергій Ярошко18-Nov-22 7:35
professionalСергій Ярошко18-Nov-22 7:35 
GeneralRe: Figure 1 Pin
André Marcos (Advisor)21-Nov-22 9:33
professionalAndré Marcos (Advisor)21-Nov-22 9:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.