The Isolated Rooms
A horror game for mobile, live on the Google Play Store.
Download on the Google Play Store
Mobile Optimized
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.
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.
The onscreen joystick was created following this YouTube tutorial. Download the C# script used, here.
The camera movement is controlled by this JavaScript script that reads the accelerometer data of the device and rotates/tilts the camera accordingly. This script also works when exporting for VR(Oculus, Cardboard, Gear, etc.).
Camera Settings
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.
Build Settings
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.
Scripts Used
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”.
- A show object on trigger script to show an object(s) when the player triggers it. Download “GameObjectShow.cs” here.
- A hide object on trigger script to hide an object(s) when the player triggers it. Download “GameObjectHide.cs” here.
- A text display script to show text onscreen after being triggered, Requires a Text object present and attached to a Canvas object. Download “TextTrigger.cs” here.
- An explode timer script was used twice to enable explosion sound effects, explosion particles, lights, exploded objects, and camera effects. Download “ExplodeTimer.cs” here.