Just over a month ago I found myself looking to scratch a destruction itch that I didn’t know I could have, so to satiate it I had to turn to the only game (that I am familiar with) that could do this: Blast Corps on the Nintendo 64. I was immediately sucked in again. So much so that I decided to get all of the platinum medals and (subsequently) 100% in the game. Needless to say that I was once again hooked. As I was working on my 3D platforming game Besus: Journey for Vitality at the time, my brain was set in game developer mode. So as I was playing through Blast Corps, I was also breaking down how the various elements worked and how I might go about programming them.
Roughly a week after playing through Blast Corps again I decided to actually follow-through with trying to prototype something like it. A few hours later, I ended up with the prototype that is seen above. Let’s break down the basics of what is happening here:
- The vehicle itself is a rigidbody, with movement being applied through AddForce (VelocityChange) and rotation with transform.Rotate.
- There is also a collider with a “Destruction” script attached that will check that the collision occurred on the “demolisher” collider and pass the damage through to the building script.
- The building script has a max health value and after a collision occurs with the “demolisher”, we subtract the health set on it.
- If the building runs out of health, we do the following:
- Spawn the explosion particles at random locations within the bounds of the building collider.
- Instantiates (remember, this is a prototype) the debris objects (at this point they are just flat-textured rocks) within the same collider bounds as the explosions.
- The debris itself is set to despawn after a set amount of time by reducing the local scale and then destroying the instantiated object.
- Lerp the y position of the building from its starting position to value closer to the ground.
- Destroy the building object.
After overwhelmingly positive feedback on /r/Unity3D for this simple prototype, I decided to expand on it.
I created individual blocks/pieces for the buildings now so that sections of larger buildings could be destroyed while leaving the remaining sections standing (like in Blast Corps). Even though there is a lack if internal detail, that will likely be out of my scope for this project. To make this all work, I have it set so that pieces on the bottom call the destroy function in just the pieces stacked on top of them. This means that even if the player hits a jump and takes out the middle of the building, the pieces which they never hit on the bottom will still be there. The same debris, explosion, and lerp is taking place as was originally implemented in the buildings, only now it’s for the individual pieces. The major difference being that I am now using pools to spawn/despawn the debris and explosions as there are now considerably more of them being spawned. As I was working on this, I originally had collision on the debris, however I found that the bulldozer kept getting hung-up on it killing all momentum. Since I wanted to retain the “indestructible” feeling of Blast Corps, I added the debris to its own layer and removed collision between it and the player/vehicle layer.
Now that I had the destruction portion of it (or at least the foundation for it) set, I turned my attention to the vehicle control. In these early version it was just a rigidbody so it was prone to tipping over. The up-righting-itself check that I had worked, but it still felt clumsy and the vehicle would still barrel roll and bounce uncontrollably until the self-righting kicked in. To reference back to Blast Corps, you never felt out of control and as a result, felt indestructible. So I decided to lock the rotation of the primary rigidbody and to make it feel less stiff, use a Raycast to align the model to the surface which it is currently driving on. In addition, I made the model itself a child of the main vehicle object so that I could control just it for things like bounces and falling rotations. This would keep the player in constant control of the vehicle and still create a sense that the vehicle was real. Overall I spent considerably more time on the feel of the vehicle (and likely still will) than on making the destruction happen.
With the main features of the game fairly well established, I turned to some of the more minor things.
- Explosive Semi Trailer: equivalent to the nuclear trailer in Blast Corps; the danger present in each level which upon collision will end the current level.
- Target Indicators: a mesh that gets moved to the nearest building in the path of danger (in other words an essential building that needs to be cleared).
- The nearest is determined by comparing the vehicle/player position to a list of all gameobjects flagged as “danger” in the current level.
- Vehicle switching: press a button and the player leaves the vehicle allowing them to walk around on foot and enter different vehicles.
- I used a lot of the core movement code established in my 3D platforming game to control the player. He does not have any other abilities beyond entering vehicles.
- Simple destructible objects: like the building but any collision (no matter how hard) will destroy them. Used for objects like fences and boxes.
I’d hate to think of Besus: Journey for Vitality as my learning project, but I have found implementing all of the above features infinitely more easy for this project now that I have a solid understanding of both Unity and C#. My next major obstacle will be creating the level-select and level complete result screen UI’s (and I would be lying if I said I was looking forward to those). 🙂