A couple of weeks before Christmas Unity dropped a public preview of the latest update to their engine. Along with this they announced a competition to make a game using a preview of the Flash exporter functionality. So I set to work making my entry, Covert.
Inception
The game idea spawned from my love of the original Deus Ex game. My favourite elements being the sneaking around, hacking computers and guessing the keycodes for doors. So I wanted to make a game that just focussed on those elements. I figured that without weapons of any sort, coupled with a 1 shot death means the tension should carry the gameplay enough to make it fun. Without further ado, lets get on to some of the technical tricks I came up with that made this game possible.
The Cameras
The cameras field of view and visible cone was done using raycasting. A LOT of raycasting.
I used a variable amount of raycasts per camera ( depending on how many cameras there were per level) then just set a value for the field of view. The camera then steps across its field of view raycasting at regular intervals and storing the point it hit. If any of those raycasts happened to land on the player I trigger the alarm. Then finally I take all the raycast hit points and triangulate a mesh out of it to show the visual fov cone.
So yes, I was doing over 100 raycasts per frame… in flash. I was really impressed with the performance considering how much I was smashing the CPU with unoptimized prototype quality code.
Enemy AI
The new navmesh feature came into its own here. Unity has basically made it possible to develop a relatively advanced AI in about 3 minutes. I couldn’t believe how eat it was to plug in just one behaviour controlling the alert state of the enemy (either stopped, patrolling or alerted) drop a few waypoints in the editor and let the navmesh do the rest.
The only limitation I came across was for areas on the navmesh you want to toggle. (in my case , the doors). The only way I could find to have some navmesh areas toggle was to put a small section of floor under the door on a different navmesh layer.
This effectively blocks the AI until you add that layer to the allowed path ( when the door opens). A decent enough solution but there is a hard limit of 32 navmesh layers so if I had a giant level with hundreds of doors I would of had to find another solution. Luckily, I didn’t. I think the highest door count I got was on the last level it reached about 20. And after designing that one I decided I didn’t want any levels bigger than that!
When the player opens a door I add the assigned layer for that door to the walkablePath of all the enemy agents in the level with the following code:
public void RemoveLayerFromNavMesh(int layer) { foreach (NavMeshAgent enemyAgent in allEnemyAgents) { enemyAgent.walkableMask += 1<<layer; } } |
Image Effects
Not being completely confident with the performance scope of the Flash player I wasn’t sure about using all the advanced image effects with Unity Pro. I kept away from the heavier effects like depth of field and vignetting but really wanted to have some visual gloss so found some cheaper ways to imitate post processing.
Firstly I used an alpha plane with an inner glow created in Photoshop over the whole scene to create a fake vignette effect that was on through the entire game.
Secondly a Mobile Bloom (found in the Angry Bots sample project) was added that is cheaper than the full bloom/flares effect but has less fidelity. It didn’t seem to impact the frame rate much and was more than happy with how it looked

Before & After Mobile Bloom Effect
When viewing through the cameras (and the computer screens to a lesser effect) I wanted to add a noise pattern. There is a noise image effect but as I was trying to stay clear of heavy post processing I used a much cheaper method that looks fine for the purpose.
Simply adding a plane over the entire area of the UI camera with a simple noise texture created in Photoshop and using an Additive shader creates a pleasing (albeit static) noise effect. The final step was adding some movement to the noise effect. Just using the UV offsets in the material and randomizing the values creates a random and totally believable noise effect with no post processing:
void Update() { Vector2 random = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)); renderer.sharedMaterial.mainTextureOffset = random; } |
UI
I couldn’t do the post mortem without giving a nod to a plugin that made the game possible which was NGUI. After the Flash exporter was added to the developer preview of Unity I think it took the creator a couple of days to re write his code to support the Flash platform. I had previously started using it as the support he was offering impressed me so I was really happy to see he had chosen to support Flash so early on. All of the UI was built on the NGUI system and it’s the UI I now use for everything :)
What Went Right
With the insanely strict deadline imposed by the competition it seemed like an impossible task to create a game from start to finish with enough depth to shine in a competition with a grand prize of $20,000 but thanks to the timing (done over the Christmas break) I had a lot of free time and not too many work commitments so I worked on this project 24/7.
The actual game idea and theme was something I’d had in the back of my mind for a while and had wanted to develop since before the competition so I didn’t spend any time coming up with a theme I just started working on it right away.
The graphic style came together very quickly and was inspired quite heavily from Frozen Synapse. A game I’d played a little of but appreciated the minimalist (and very blue) styling throughout.
Problems
The Flash Exporter (which is still a preview) has some limitations which meant I ran into a few hurdles a long the way. Certain methods aren’t included in the Flash .net subset including System.Array which I use quite a lot for managing native array types. Instead of these helper methods I had to roll my own solutions for dealing with array functions like copying and resizing.
One day before the submission my entire UI exploded for reasons I have yet to work out, and due to the timing I was back at full time work so had to do a days work, do an all nighter on Covert and then back to work for another day. It was a really tough slog but I was very happy that I managed to re make all the UI through the entire game and get my submission in about 30 minutes before the deadline.
Conclusion
Overall I was really happy with how it came together, in terms of the Flash export functionality I was extremely impressed. Converting an old game to use the Flash exporter may leave you with a lot of errors and unsupported features that prevent you from exporting, but creating a game from scratch with the Flash exporter in mind really isn’t so bad. Doing test exports frequently should mean you’ll find any issues early on and can work round them.
Thankfully the guys at Unity enjoyed my game enough to give it a runner up slot in the competition and provided me with some additional Unity licenses which was great. So thanks to everyone at Unity for doing this competition and providing us with a great toolset for making Flash content!
Great work as usual, so you definitely don’t have a small team of illegal aliens tucked away in your attic?
If you need to optimise the cameras have you considered replacing the ray-casting with a mesh trigger in the shape of the camera viewing frustum, then if the player triggers a ray cast/scan.
Would a two layer solution work with the doors, an open and closed layer and you just re-assign the appropriate door to the layer?
PS Keep up the great work!
hehe nope, no small team of aliens :)
the cameras are done with raycasts because the camera rotates and the world is dynamic. i.e. if I open a door the cameras line of sight will change.
For the navmeshes, changing the layer of an area of the navmesh would require you to rebake the navmesh data which currently can only be done at authortime, not while the game is playing.
Thanks for your comments!
hey bro can you do a tutorial on how to creat a game like this :) that would be amazing ♥ , i got studies project to do and i prefer to do a game as my studies project want it to be just like this MGS style ♥
here is my facebook profil we can talk if u want :) https://www.facebook.com/seifedine.tamallah