Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Syncing a Rhythm Game

Discussion in 'Editor & General Support' started by Sharpevil, Feb 5, 2014.

  1. Sharpevil

    Sharpevil

    Joined:
    Dec 5, 2013
    Posts:
    22
    Hey all. As an exercise in expanding my knowledge of Unity, I've decided to try to make a small rhythm game. Nothing too complicated. Enemies appear; Press a button on the beat to shoot them. Looking for info on this topic, though, I find pretty much only old knowledge with a range of answers.

    So, what's the current best way to sync a rhythm game? The game is being designed to run in a web browser, and I will probably be using an MP3 for the music, though I might be able to change that if it's an unsuitable format. If I've forgotten to mention anything really important, let me know.
     
  2. Sharpevil

    Sharpevil

    Joined:
    Dec 5, 2013
    Posts:
    22
    Ended up on page 2. Nobody has any info to share?
     
  3. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,302
  4. Sharpevil

    Sharpevil

    Joined:
    Dec 5, 2013
    Posts:
    22
    Thanks for the info! Just about all of this seems to have to do with measuring the audio spectrum, though. I'm looking for something more like timing events to certain times in an audio file. Measuring the audio is useful, but I'm not sure how I would give the player a good on-screen guide leading up to the beat with that.
     
    KUFgoddess likes this.
  5. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,302
    If you know in advance the times in an audio clip that you want to trigger events, then you can map those relationships in a list of objects associated with an audio clip.

    Class would only need two members
    EventReference (reference to a method)
    Time Or TimeSample

    You can use the audiosource time or audiosource timesamples to track where you are in an audioclip that is playing.

    You would sort the object list by time/timesamples asc
    You would check in update if the current time is more than or equal to the relationship time of the first object in the list associated with the clip that is playing.
    If it is, then you would fire the event and remove that relationship object from the list.
     
    Last edited: Feb 6, 2014
  6. Watapax

    Watapax

    Joined:
    Sep 3, 2013
    Posts:
    34
    Hello , i been working on a rhythm battle game, try the webplayer here: www.tipografico.cl/pelea2 . What i do is map the entire song in adobe Soundbooth pressing the (*) key in the numeric keypad, so its create a marker whit the timecode , then i copy all those markers in a txt file so i can read them with c# and make a float array with all the timecodes. Then with a Coroutine loop the timecode array so instantiate enemies when the time is equal or major to the timecode in the array. I hope this can help you.
     
    KUFgoddess likes this.
  7. DHARMAKAYA

    DHARMAKAYA

    Joined:
    Dec 1, 2014
    Posts:
    59
    Wow, that is an interesting method. Any reliable onset beat detection scripts or midi file to event scripts on the Net these days?

    Thanks in advance!
    @Watapax
     
  8. Regen_erate

    Regen_erate

    Joined:
    Dec 12, 2018
    Posts:
    19
    I made a rhythm game in Scratch, and I use a variable that is constantly increasing. The notes spawn when the increasing variable is equal to the next value on the beat map, generated by custom blocks.