#Unity Rhythm Game Timing
1 messages · Page 1 of 1 (latest)
when realistically I want them like this:
My code for spawning notes is something like this:
if (GetAudioSourceTime() >= timeStamps[timeStampIndex] + noteOffset)
{
Debug.Log("trying to load a damn note");
jsonLanes[laneStamps[laneStampIndex]].CreateNote(timeStamps[timeStampIndex]);
timeStampIndex++;
laneStampIndex++;
currentLine++;
}```
GetAudioSourceTime() is simply just cs return instance.song.time
Can anyone enlighten me on some ways to make note spawning more accurate?* I've even tried making GetAudioSourceTime return:
return instance.song.timeSamples / instance.song.clip.frequency```, but this yields a slightly more accurate result, although still noticeably off.'
How are your note positions calculated?
can you elaborate what you mean by that-?
like, where they spawn?
No, like how their position changes as time passes.
about that...
transform.localPosition = Vector3.Lerp(Vector3.up * JSONBeatmapLoader.instance.noteCreate, Vector3.up * JSONBeatmapLoader.instance.noteDestroy, t);
How's t obtained?
oh t is ``` t = (float)(timeSinceInstantiated / JSONBeatmapLoader.instance.NJS * 2);
timeSinceInstantiated is obtained through storing GetAudioSourceTime() when the note is spawned
NJS is just note speed (something like 1.875 right now)
Well there's your problem
Imagine your game lagged, and you note spawned 10 ms late, then it will start at the starting position 10 ms late, and reach the end position 10 ms late.
In a rhythm game, timing is not managed like this.
when you put it like that, that makes sense
if the answer is what i think it is, surely i can just replace assign timeSinceInstantiated as the timeStamp that the note should be spawned at, right?
Basically yes.
But to get more in depth with how timing is managed in a rhythm game
You first obtain a sync point between your audio time and game time ("audio time 1234 is game time 5678")
Then your entire game is driven by game time and game time only.
Your beatmap requires a note to spawn at audio time x, then use the sync point to calculate the corresponding game time, and then everything from then on operates solely in game time.
A subtle detail is that you do not use audio time as the driver of the game, but rather game time (more specifically, game time at start of the frame)
This is because depending on audio engine, audio time can still progress in middle of the frame, causing the notes that are updated later in the same frame to possibly shift.
oh yeah, that's a thing isnt it? i forgot