To make a first person mobile game, everything but the bare essentials must be stripped away. Mobile devices are limited in processing, graphics, and screen space. Therefore, creating a good-looking and smooth-running game is quite a challenge for those unfamiliar with the intricacies of game engines. For instance, we need to compress textures from megabytes to kilobytes, eliminate post-processing effects, and simplify physics colliders.
Four screenshots of the game in normal Android mode. The gray circle in the bottom-right corner is the joystick for controlling the player.
Setting Up the Player Object
A simple player object consists of a camera, a physics collider, and a light source (for a flashlight).
To play the game, the player needs to be able to move and look around. In the example, I use an onscreen joystick and the device’s accelerometer to move the player and the camera.
Change the clipping plane property of the camera so that the far value is as small as possible. This decreases how far the camera renders at any given moment. An easy way to hide this effect is to add fog to blend the clipping to black. (I’m using radial fog—not the built-in distance based one.)
Setting Up an Optimized Game World
Set non-moving objects to static. We’ll see a setting later that combines static meshes to optimize performance.
When importing models, set mesh compression to high to allow Unity to optimize the mesh. Overall, this will decrease the triangles/polys rendered every frame.
Resize textures to be as small as possible. All textures in the example are under 800kb, such as the walls, floor, and timber. Also, remove all but the albedo texture. Rendering normal maps puts additional strain on the device.
Mesh colliders are what Unity creates to enable physics on objects of unique shape and size. Using them on mobile is not recommended. I recreated all the colliders with box colliders instead and this helped the terrain render with a much higher FPS. If physics is is taking up a large percentage in the profiler, this may help. However, this step may take too much time depending upon the complexity of the scene.
Lastly, the build settings of your project should look something like this.
Pixel Light Count and Texture Quality should be as low as acceptable.
Anisotropic Textures and Anti Aliasing should both be disabled along with Soft Particles and Realtime Reflection Probes.
Shadows should be set to hard or off completely, at the lowest acceptable resolution, and with a limiting distance similar to the clipping plane distance.
To create the game, several simple and reusable scripts were utilized on a plane with a box collider set to “Is trigger”.
A jumpscare script can be used so that when the player walks through it, a sound clip is played and another GameObject/Light appears. The tutorial can be found on YouTube here, and the added functionality for lights can be downloaded here “JumpScareTrigger.js”.