A First Person Shooter Game Using Realtime Map Locations

by Vaibhav28 in Craft > Digital Graphics

1472 Views, 7 Favorites, 0 Comments

A First Person Shooter Game Using Realtime Map Locations

Screenshot 2020-06-28 at 9.45.18 PM.png

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).

Adding Game Component

Screenshot 2020-06-28 at 9.27.24 PM.png
Screenshot 2020-06-28 at 9.20.01 PM.png

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

Adding a Game Character

Screenshot 2020-06-28 at 9.39.10 PM.png
Screenshot 2020-06-28 at 9.07.16 PM.png

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.

Configuring Mapbox.

Screenshot 2020-06-28 at 9.59.39 PM.png
Screenshot 2020-06-28 at 10.02.14 PM.png
Screenshot 2020-06-28 at 10.02.34 PM.png

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.

Adding Map Component

Screenshot 2020-06-28 at 10.14.27 PM.png

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.

Customising Map Component

Screenshot 2020-06-28 at 10.30.47 PM.png
create-a-map-getting-started-unity-7.png
create-a-map-getting-started-unity-6.png
create-a-map-getting-started-unity-10.png
Screenshot 2020-06-28 at 10.38.26 PM.png

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).

Rendering Buildings

Screenshot 2020-06-28 at 10.40.34 PM.png
First Person Shooter Prototype using real map location

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.

Cheers!