paint-brush
How I Built A 2D Platformer Using Unity3D game engine by@anshuman-pattnaik
164 reads

How I Built A 2D Platformer Using Unity3D game engine

by Anshuman PattnaikMay 10th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Forest Assassin is a 2D adventure platformer game with easy controls and fun gameplay, which helps every one to get started, this is a classic platformer game with wonderfully designed characters and world.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How I Built A 2D Platformer Using Unity3D game engine
Anshuman Pattnaik HackerNoon profile picture

Forest Assassin is a 2D adventure platformer game with easy controls and fun gameplay, which helps every one to get started, this is a classic platformer game with wonderfully designed characters and world.

To complete the game collect all the coins and the trophy try to collect all 100 gold coins to become the highest scorer in this adventurers platformer game, on your way you will face many obstacles and enemies and use your sword to fight with the enemy.

How to play the game on desktop browser?

To make it easier for the user I have also published as a desktop browser game because people always love to play browser games and the reason is its quick easy no need for any types of installation.
Currently, the game is available at  and it supports all the modern desktop browsers.1. To move use [ A ] [ D ] or arrow keys2. Use [ SPACE ] key to jump3. Use [ W ] key to attack4. To finish the game collect all coins and the trophy

How to play the game on Android device?

Forest Assassin is also available for Android devices and on the smartphone user will get the feelings of a classic platformer game. So please download the game and share your experience.

1. To move use [ LEFT ] & [ RIGHT ] arrow button

2. Use [ UP ] arrow button to jump

3. Use [ SWORD ] button to attack

4. To finish the game collect all coins and the trophy

How to Build a 2D platformer game using Unity3D?

game engine is a great platform to build a 2D or 3D game because it provides many major components such as physics, animation, cross-platform support and many more. And before starting to build any types of game the very first thing you need to do is design a  which means you need to build the idea behind the game which will help you to develop a successful game and always try to remember while designing a  make it simpler and don’t make it complicated otherwise it will be quite difficult for you to finish the game.
If we see an example of a legendary  which you often play on Google chrome browser when you don’t have an internet connection and this game is the best example of a 2D platformer game and if you look at the game then you noticed the game is very simple and easy to play all you need to do is press the SPACE bar on the keyboard to avoid the obstacles and earn points.The similar approach I also follow while designing this game at the very beginning my goal was to build a simple 2D platformer game so that any types of user can play and have fun and also it should help me while building this game.

Forest Assassin Game Theory

There is a king who hunts for the treasure and during his mission, he will face many enemies and there will be a 3 minutes time limit to complete the game.

And that’s all the theory behind my game and you should also follow a similar approach while building your game.So now let’s discuss what are the tools and techniques behind Forest Assassin game?


Tools & Techniques

In every 2D platformer game, there are many components which we need to build to finish the game and these components are the major elements of every platformer game.1. Character Movement2. Character Death3. Character attack4. Score Counter5. TimerSo now let’s discuss how I have implemented all of these components into my game one by one.

Character Movement

To move a character in the game you need to have a script which will control the character to Walk, Jump, Crawl and so on and also it requires physics.
To control the physics Unity provides a component called  which handles lots of fundamental physics like force and acceleration and this component you can use with anything, which you want to interact with the physics.At last, it requires a floor where the character can able to walk and in Unity it’s called Collider component and there are many different types of collider are available such as , , etc.When you have all of these elements in place then you can able to move your character.

Character Death — (Game Over)

In this game, the character can only die when he touches with the enemy or with the water and to handle the trigger between the collider Unity has an API called  which will handle the trigger between the collider and after the collider, it will send a message to the Collider2D parameter which we can use to decide the death of our character.

And to make it organised I have assign tag name called ‘Enemy’ so that in future if I will add one more enemy then all I need to do is assign this tag name to this component and it will be handled through the Script.

Character attack

Character attack is the most crucial element in every game because this is how you win the game and while building this component the two things you need to understand first is the animation and second is the attack script.To make the  in 2D first you need to gather all the  and add it to the animation component and create your animation and later you can use it through the script.


While writing the attack script a few things we need to know such as Attack range and attack point because it’s quite important that from which position the character will set his attack vector and in this game Sword is our attack vector, so when the character uses his sword to attack the enemy then we need to know the range and the point of the attack so that we can successfully launch our attack.To calculate the attack range and point Unity has an API called  it will return a list of colliders which falls with the circular area and when we get all the colliders then all we need to do is start a loop and within the loop destroy the enemy game object.And to give more clarity to our attack I have created a blood  which will appear on every enemy death.

Score Counter

If you understood the above two techniques (Character Death & Character Attack) then to implement the scoring functionality it’s quite easy as we need to follow a similar approach. When the character and the gold coins collide with each other then I am calculating the score to +10 through the script and again here also I am using  API.
To display the score on the game I have used  component which comes under .And the same scoring variable is being used in all three components (You Win, Game Over & Time’s Up).

Timer

To implement the timer functionality Unity has an API called  which is used to create a parallel action and can pause the current execution and then continue where it left off and all the coroutine function is declared with a return type of IEnumerator with the yield return statement.
In this game, I have set the timer to 3 minutes and when the game starts immediately it will start the coroutine function and calculates the timer and when the timer reaches zero it will call  function.And again I have usedcomponent to display the time on the game.

How to publish for WebGL?

Unity has build option which allows publishing content as Javascript programs and internally it uses HTML5/JavaScript, WebAssembly, WebGL rendering.In today’s modern web browsers by default enables and it’s quite helpful to run Unity application on the browsers.
To run a application we need to run through a local server and in this game, I have  as my server but you can also use any other scripting languages.

Open Source

I have made the complete development open-source on my  so that you will have a clear understanding of every component of this game and also I hope it will give you an idea to build your own game.So this is the overall explanation of , I hope you understood the tools and techniques behind this game if you find any issues then please feel free to raise an issue on .Enjoy the game and also share this game with your friends.Thank you & Happy coding :)
바카라사이트 바카라사이트 온라인바카라