Last week (or two) I’ve been working on various aspects of the tank game. There have been quite a few changes and here’s a quick run down:
Unity 5 came with loads of goodies I didn’t have back when I started the project. One of them is the improvement of the graphics engine and the addition of physically based shading (and global illumination). Others are the availability of image effects and reflection probes in the free edition of the engine.
After tweaking materials, sky-boxes and lighting settings a little the effect was mind blowing. The second image is a bit of an oversell as Unity 4 did have reflective shaders (but it wasn’t that easy to set up, and also they didn’t blend reflections from different cube maps).
Among everything else I made the water look nice. By using both the main and secondary normal maps on the standard shader and animating the two offsets to go in different directions you can achieve this effect:
…which is pretty much what the legacy “basic water” does, but better as it works with the standard shader instead (C# code here).
I wanted to keep the toony look so I went ahead and added a few fake image effects on top of everything :
- an exaggerated ambient occlusion to increase the presence of blackness (and the contrast a bit).
- a bloom effect that makes bright areas look even brighter;
- anti-aliasing; and
- a bunch of different blurs… just because
With the new terrain and revamped physics movement it becomes easy to get stuck in a hole (which is far worse than getting destroyed). To fix that weaggles can now get angry and explode in rage, destroying everything nearby… just like bombs (they even get the same red coloring). The explosion doesn’t happen instantaneously, you have to charge it for 3 seconds by holding a button, and you can cancel it at any time by releasing the button. You can’t take the enemy with you on reflex right before they shoot you, but you also won’t explode by accident. Despite the charging time, it’s a great utility that’s always available when you want to blow things up.
Another gameplay change is with the bullets. They are now truly physical (and along with them pick-ups became rigid bodies as well). What this means is that bullets are controlled by forces and also upon collision apply force to other rigid bodies they come in contact with.
This new mechanic allows you to push object from distance, ones you cannot reach otherwise or ones you don’t want to approach (such as bombs). When first shot bullets are unaffected by gravity (and behave like they used to), when they hit something they apply damage, ricochet in a random direction, fall to the ground, and remain as harmless rigid bodies for a while. This is interesting because for example you wouldn’t be able to push a crate by shooting directly at it (as that would break it), but if there’s a convenient wall next to it you can bounce bullets off it to make the crate move.
Did I mention that bullets now have a new model, leave a trail and create sparks when they hit something?
Last but not least I managed to get it running on Android. I tried building the game on Android right after I applied all the fancy graphics… big mistake. It was running with a frame rate of about 3 FPS. After reverting all that and reducing the terrain quality (as its resolution is pretty high) it was still performing poorly. Profiling showed that physics was eating the CPU, after reducing the quality of the physics simulation it now runs at 20 FPS and it looks something like this:
At first neither portrait nor landscape looked right on my device, the camera was positioned wrongly. As a generic solution I animated the camera with the aspect ratio as a control variable so it should now look right on any aspect ratio (regardless of the device).
Another thing I did in relation to mobile was to atlas the textures and start putting everything into a single material for which the new rendering engine proved again ingenious. Just by using the new standard shader and a single material you can render all diversely shaded objects in the scene which was not possible with the many families of shaders in Unity 4. When switching to mobile you can now simply change the shader of a single material, which is amazing.
I plan to dig into multiplayer again sometime soon, the new networking API solves a lot of obstacles I had stumble the last time I tried it. It is now quite easy to make mixed local-network multiplayer and also quite easy to allow players to join at any time.