Master Of Animation, Games & Interactivity
Master Of Animation, Games & Interactivity

During the final weeks of semester, I worked on game mechanics and creating a playable prototype. Last week, I had successfully created two particle systems to handle the "world rocks" which existed in the world and could be "picked up" by the player, and "model rocks" which were spawned on the player during collision with a world rock.

The "world rocks" had only one collision: with the player. They did not interact with the world at all. I wanted to change this and make them respond to gravity, so that they would fall to the terrain. I would also have to allow them to collide with the terrain. I switched their collision trigger to the terrain, then tweaked the project's global settings and applied a gravity constant to all objects (unbeknownst to me, this would cause problems later), which made the rocks fall to the ground and, unexpectedly, bounce. Furthermore, since I had tweaked how the world rock particles were colliding (their collision trigger), they were no longer destroying themselves on collision with the player - so the world rock continued to collide with the player and spawn particles infinitely. I tried to have the player detect a collision with the particle through code instead of the collision system, however I could only get the player to destroy the entire particle system, and could not access an individual particle in the collision. After digging through some documentation, I discovered that there was no way to do this in the current supported versions of Unity (2019). I was, however, able to find a recent forum post with an issue similar to mine, in which a Unity developer responded with a playable alpha build which incorporated changes to particle triggers, which would support multiple triggers with multiple different objects, and opened up more access to individual particles in code. I thus upgrade my project to this alpha build. This, for whatever reason, caused a few of my shaders from the Forest environment (the water) to break, which I had hoped to return to and allow the player to explore this region with the new rock gathering functionality. I was unable to fix this and returned to my original task. I was able to set up these new particle trigger collisions with both the terrain and the player, allowing the rocks to sit on top of the terrain, and also be "picked up" and destroyed by the player.

Now that the particle gathering was working as intended, I wanted to introduce more mechanics to the prototype: jumping/flying, and changing the terrain (spawning grass and changing the texture). While the code for jumping/flying was relatively simple to implement (I could use very similar code to the character controller I had created in Godot), I found that I was encountering a strange bug: the longer I flew for, the greater a kind of "gravity" force became, pulling the player back down. After much bug-testing, I finally realised it was because I had turned on a "global" gravity for the rocks. I saw no solution but to turn this back off (which unfortunately meant that the rocks, once again, were floating, and meant that a lot of my earlier research, headaches and code was for naught). However, during testing, I actually quite enjoyed flying to reach the rocks, and decided to embrace this functionality and even increase the area over which the rocks spawned. 

I then turned my attention to the "grass" mechanic. I dived into the documentation for the Terrain editor and "splatmats", and was eventually found success: I translated the player's co-ordinates to terrain texture co-ordinates, looped through the terrain map to find its values, and changed them to a different texture where the player was standing. I was able to do a very similar loop for the "paint details", which can create small textures (ie. grass/flowers/details) on the terrain. I was extremely happy with this result - from the beginning, this was a mechanic I had always envishioned to have in the final project. I decided to tie my two mechanics together, and have the number of rocks on the player's model effect the area of grass/texture that was changing. I initially made the number of rocks have a smaller effect, but it made gathering each rock feel less significant, and so I made the number of rocks and terrain tiles changing directly proportional to each other at a one-to-one ratio (including that when the player has 0 rocks, 0 terrain tiles would change). 

Finally, I wanted to tie the prototype together with sound and music. I sourced three sounds from freesoundorg.com: a pickup sound for gathering the particles, a wind effect for when the player moved, and a background ambient soundtrack. I quickly realised the pickup sound effect was too repetitive, so programatically shifted the pitch every time it was played. I tied the wind effect to the player's movement: it grows louder when the player moves, louder still if the player moves fast (holds shift), and fade away when the player is still. I also added a stereo sound effect to both the wind and the ambient music to create a more immersive environment. 

CREDITS (Sounds):

  • Background Game music: "The Elementary Wave 11v2" by Erokia - https://freesound.org/people/Erokia/sounds/424319/
  • Rock pickup sound effect: "Item Pickup" by TreasureSounds - https://freesound.org/people/TreasureSounds/sounds/332629/
  • Wind movement sound effect: "tree-leaves-rustling.aif" by Spleencast - https://freesound.org/people/Spleencast/sounds/87289/

About This Work

By Natasha Vranic-Peters
Email Natasha Vranic-Peters
Published On: 05/06/2020