Devlog 2 (Coding) - Beat Tracking


One of the core systems of any rhythm-based game is how functions are timed to the beat of the song. For this, we need an accurate and fool-proof method for keeping track of the song's beat.

In our previous coding devlog, we ran into a critical issue where the implemented beat tracker seemed to fall behind of the song ever so slightly, and even be behind an entire beat by the end. At the time, the cause of the issue was unclear--we speculated a few reasons such as computation speed within Unity or variables relating to managing the song being handled in multiple scripts . Upon further investigation, we found that it had to do with the current of method of calculating beats that stores it in a separate variable and resets it at each beat. Storing the song's timing in a separate variable can be finicky because any calculation that happens outside of AudioSettings.dspTime will be affected by Unity's frames, thus causing a slight delay in the beat tracking.

To solve this issue, we instead track the song position as an integer and use a modulus operator. This calculation can be interpreted as whether the song position (current beat number) is an odd or even number.  This way, we have an accurate, black-and-white way to switch back and forth between being on-beat and off-beat that updates based directly on the project's AudioSettings.dspTime and isn't affected by Unity's frames.

In addition, we also add a delay after each player's attack to discourage spam-pressing the attack key.  After a successful attack, there is a 0.4s delay until another attack can be attempted. However, this 0.4s window does not equate to how often the player should be attacking--it is largely a way to prevent more than one player attack from being instantiated  beat. On the other hand, after missing an attack due to attacking off-beat, there is a 1.0s delay until the player can attack again. If the player tries to attack before this 1.0s delay is over, the delay will refresh. Only after the player waits out this 1.0s delay in its entirely can they continue attacking as normal.

Files

Prototype 1.1.zip 33 MB
Oct 24, 2023

Get Joseph Kills Lucy

Leave a comment

Log in with itch.io to leave a comment.