Introduction: A First Person Shooter Game Using Realtime Map Locations
I made this project few months ago(when covid19 lockdown began) and to be honest it was quite thrilling to make something like this from scratch. The idea was to bring real maps into the games and have fun. I ended up building a prototype for the same which I will be covering in shortly.
I'll start with prerequisites installed in your system before I begin
1. Unity game engine (A free student version is available which can be easily downloaded here)
2. Mapbox SDK (I used mapbox as it was readily available and has a free tier as well).
Step 1: Adding Game Component
1. Add a base game component (floor) initially.
Steps: Go to hierarchy panel and create a plane for the game character to reside in.
this floor will act as a reference for the game character and is just a temporary floor and will be replaced with map later
Step 2: Adding a Game Character
Now Adding a game character is quite complicated if you dive in to details (adding motions, animations etc) but thankfully, you can avail the prebuilt ready to use game characters (called assets) from unity asset store.
If your'e really interested there are tutorials on building your game character from scratch on unity learn.
But for now we will go ahead with ready-to-use assets.
Just go to the window tab and click on asset store (it'll require a sign in) or you can go to Asset store , download your favourite asset and import it manually in the project.
From there you can select tons of game characters. For this example I chose "Toon Soldiers WW2 demo" which is free.
Step 3: Configuring Mapbox.
Once the player movement and camera settings are adjusted (Player movements and camera adjustment scripts must be dragged and dropped to the game character prefab), we will begin with replacing our base game component floor (from step 1 ) with a real map.
(I've made camera movements and mouse sensitivity as per my liking. Feel free to tweak the code and change it as per your requirements.)
To add a map you will require a mapbox sdk which can be easily downloaded here.
Then you will need to import this SDK into your unity project by
Assets > Import Package > Custom Package, then select the package file to import.
Once you import mapbox package, there will be an additional mapbox menu item.
Go to Mapbox > Setup and enter Access token which will be generated when you'll sign in to your mapbox account. You can also refer this incase of difficulty.
Once above steps are completed, we can move on to adding real maps into the project.
Step 4: Adding Map Component
Now we have to do is go to Project panel > Assets > Mapbox > Prefabs and drag and drop Map prefab to the hierarchy window into your scene.
Step 5: Customising Map Component
To customise the map component click the map prefab added in the last step.
This will open a inspector pane at the right hand side which will give you multiple options to customise the map.
Just go to General tab and put Latitude and longitude for the desired location.
Once done, go to image settings and change the Data Source to “Mapbox Satellite”.
Finally, open the terrain settings and change the Elevation Layer Type to “Terrain with Elevation”. (This will render a satellite version of the map).
Step 6: Rendering Buildings
However, the building will still be not rendered, to do that,
just go to Map layers tab > Feature >Add feature (select buildings) and hit play.
You'll see the buildings will be rendered now.
You can change the setting for the buildings (scale factor, height, light settings etc by going under building feature ).
completing above steps will build a prototype of a First Person Shooter Game based on real maps.
For reference I have made whole project available on Github
You can check that out here
Feel free to reach out to me incase of any concerns.
Participated in the