reverie3d
reverie3d
Reverie
1 post
Hello, I'm Reverie, 19m. I love computer graphics and retro video games!
Don't wanna be here? Send us removal request.
reverie3d · 2 months ago
Text
Micetro Devlog #1 - A Rhythm game made with Unity
Tumblr media
Micetro is a rhythm game about a mouse conductor preparing for his upcoming concert. So far, the movement, dialogue and the rhythm mechanic have been made. The rhythm mechanic has a complex level designer tool for it. This devlog will not be a line by line tutorial, but rather an overview on the tricker aspects of making the rhythm game mechanic, skipping the more tedious aspects of it.
youtube
While many tutorials handled level design by changing the spawn time instance variables through the Unity inspector on a spawner class, it made it difficult to properly construct more complex levels with ease. So I went ahead and created my own level design engine for the game. Designers can construct vast and complex levels and immediately implement them into the actual game. It creates a new JSON file and stores all the note spawn times and the song of choice into it. The level design engine comes featured with a record button, so designers may press the keys they see fit while listening to the music to line it up properly. It also includes options to change individual notes, in case the designers may wish to delete them, change their positioning or create new notes. Lastly, the engine comes with a drag select function, in case designers wish to alter multiple notes at once.
youtube
youtube
The drop down menu in the inspector was created by utilizing Unity's ISerializationCallbackReceiver interface. This allows users to call functions while in the editor. Unity's ListToPopup attribute can also create a drop down menu for any list variable. Using drop down menu's is a great way to eliminate any bugs that might have been caused by typing in invalid strings.
Tumblr media
The audio is retrieved from the JSON file using Unity’s web server request. The URL can be altered to retrieve data locally on the player's computer. It is very important to put this code into a coroutine because the audio isn’t retrieved right away, and may take a couple of frames before you can use it. 
Tumblr media
Saving the data is pretty simple and requires creating a new class of your arrow data and implementing it into a JSON file. Just remember to make sure all the note times are sorted before saving them.
Tumblr media
Here I have a list of every spawner contained within the LevelSaveData and the path to the song that is being used. Inside the spawner class is a list of floats for each note that is being spawned.
Tumblr media Tumblr media
Syncing the arrows to the music is very important, and if you rely on delta time alone, the arrows will eventually get out of sync from the music. To achieve perfect synchronicity, first get the inverse lerp of 0, how long the note should take to reach its destination and how long the note has currently been alive for. The age of the note in this example, is calculated by getting the current AudioSource.time and subtracting it by when the arrow spawned. Using AudioSource.time is what will prevent your notes from going out of sync. An inverse lerp essentially returns a normalized float that measures where a point lies between two values. This value will then give us the percentage of how far the note is through to completion. Then set the current position to the lerp value of its starting position, ending position and its percentage to completion. If you find that the arrows are a little jittery, you can slowly lerp it's position between the next and previous frame so it’s never so sudden.
Tumblr media
There are 4 spawners, one for each key the player can press. Each spawner checks every frame if the next arrow can spawn yet. It does this by checking if the current time position of the song is bigger than the spawning time of the arrow, minus the amount of time it takes to reach its destination.
Tumblr media
The detector is simple and examines how close each note is to the ending. When the note is close enough, each note sends a signal to its detector to tell it that it can be reached. Depending on when the player hits the corresponding key, the note can be signaled as early, perfect, or late. 
Tumblr media
These are the most fundamental parts of the code and what is required to create a working rhythm game. More stuff has been added in such as a scoring system, notes fading out and even note falling physics when the player doesn't execute them in time. I really hope you can learn something from this devlog.
Thank you and have a great day! :D
2 notes · View notes