How I built my first Augmented Reality FPS game

Ariful Islam
Predict
Published in
4 min readFeb 4, 2019

--

One night after some intense games of foosball(or Table Football/soccer as some of you know it) and seeing the most random variations of ping-pong, a couple of friends and I went to a friend’s place to see a movie. After violating our meal plans and a good 20-minute argument, we finally decided to watch Avatar.

Apart from blue people riding horses and giant birds with their ponytails, what intrigued me the most was the carriers. I don’t know why but I thought they were the coolest thing in the world! And they could potentially be a reality soon!

Then I started to think, what if the blue people had their own ships and were fighting these gunships? That would be soo cool! I would definitely pay to see it!

Now, what do the blue people have to do with me focusing on Augmented Reality and my game?

Nothing really, but the gunships do!

Since I am looking into AR, I wanted to make an app as my first project and I am passionate about video games(not Fortnite), I thought I would make an AR game for smartphones!

The next morning I started planning the whole thing out and on paper, it seemed pretty easy. But then I actually started building it!

So I needed some sort of software platform to make it on, and for that I downloaded Unity. Right, when it opened the workspace, I had realized how difficult this was actually going to be.

I won’t talk about setting up the whole app in Unity because this will end up being a glorified Youtube-tutorial so I’ll just go over the code.

First I had to make a plane and have the camera feed displayed on that plane. That took some coding in C# and the code for the camera feed function is:

*Note the transformations depend on the platform that you are building to. For Apple make sure to display the feed upside down in Unity*

Next, the game needed some objects to be shot at! I got the gunship as a game object in the scene and then coded the movement of the gunships. Now, I wasn’t going to make them super complicated so the code is actually quite simple.

Since I didn’t want there to be only one round, I coded a respawn function that spawned a set of new opponents after a certain amount of time after all other opponents have been destroyed.

Then I thought what does every amazing game need? A big red FIRE button that fires torpedos! So I coded that into the first script.

The last part was simply making sure that on impact, the torpedos exploded and most importantly, looked amazing while doing it! I downloaded a plasma explosion effect and combined that with a collision script.

Since simply one target would be a pretty boring game, I duplicated the gunships and had 4 gunships spawn at any given time.

In hindsight, explaining it isn’t that hard however figuring it all out was pretty time consuming and lets not even talk about the frustration that comes when there are bugs in the code and it won’t build.

Since the gunships were invading the blue people in Avatar, I thought it would be fitting to call the game Invader, but since this was an AR app and I had to put AR somewhere in the name; the game is called InvadAR!(Creative, I know)

Screenshot from InvadAR

Here is a quick 15-second demo of the game

InvadAR Demo!

Also, one of the problems while running the game and screen-recording at the same time is that the “FIRE” text on the fire button seems to disappear and every time I tried to use the back camera and screen-record, the game crashed so I got around that with recording with the front camera of the phone.

This was only the first of many other AR projects to come! At this moment, I’m just polishing up the game and soon it will be available on the Google Play store(sorry Apple users)!

If you enjoyed this article and are excited about my future AR apps!

  • Give this article some claps so that I know you enjoyed it.
  • Connect with me on LinkedIn.
  • Leave some feedback through comments.

--

--

Ariful Islam
Predict

Tech enthusiast and AR developer on a journey of self-discovery and growth.