Coding C# in unity

A solo project which I completed within four weeks
The code I am most proud of is for the audio analysis and delay
Link to download unity rhythm game

Features

  • An audio analysing script which helps create a rhythm game level out of any audio of the players choice at runtime.
  • An options menu allowing the player to customise note speed, note spawning sensitivity and minimum time between note spawns.
  • A developed score system with Points, Combos, Gradings on note hits and an overall grade given at the end of the song based on the players points compared to the maximum points they could have achieved.
  • What makes this game stand out?

    I believe that my procedurally generating rhythm game is more technically advanced than its competitors for a few reasons.
  • No competitors i have seen allow the player to see a preview of what their song will be like before they confirm their options
  • They also do not have advanced customisations, having no options to change the note speed, and usually only being able to choose between an easy, normal and hard mode, which is not an ideal system for a procedurally generating rhythm game, since what is considered easy or hard depends entirely on the song.
  • Code Explanations

    Audio analysis

  • I get the current spectrum data of the chosen audio
  • I use a for loop to split the spectrum data into four hertz parameters to be displaced on each line.
  • This results in each line displaying a certain pitch of the song, for example pink notes are high pitch.
  • Then, for each of the four hertz sections I take away the current frames spectrum data from the previous frame.
  • I use this value to check if the change in spectrum data is significant enough to produce a note.

  • Audio Delay

  • A delay is required because my rhythm game has a silent backing track which spawns the notes, then an overlayed track which the player hears.
  • So I need to find the correct delay for the overlayed track, so it can be in time with when the notes reach the clicking area no matter the song or note speed.
  • To do this, I get the time in the audio that the first note is spawned, and take that value away from the time in the audio which this first note collides with the perfect clicking area.
  • Finally, the resulting value is taken away from how long the audio has been playing, and this gives me the ideal delay for the overlayed track.
  • What I could have done differently

    If I come back to this project, I think the first thing I will attempt is the long, held notes often found in rhythm games.
    If I had chosen to analyse the songs before the rhythm game level starts rather than analyse whilst it plays, I could have known what the potential points were from the start, allowing me to add a progress bar for the players overall ranking on the song.
    If I did not have other projects to work on at the same time, I likely would have finished it faster.

    To clarify

    Many have asked if the game uses some sort of audio analysis AI, it does not, it is done with code; if I were to use AI in this project I think I would try using it to separate instruments into their own lanes.