|Topic was automatically imported from the old Question2Answer platform.
I am currently working on a music game. The main game play focus is dodging objects. These objects should appear according to the music and are hand placed. I am currently placing these objects and recently noticed that the objects I place appear at a different time when I play from the start of the song than when starting somewhere in the middle.
I tracked this problem down to my current time measurement. At first I tried using the playback position as time indicator and defining the placement of the objects according to the playback position (which I get from the AudioStreamPlayer), but this resulted in very choppy movement, which I am also not sure why it occurred. (as fixing this would also be a fix for my problem) So I used the delta from the _process function to calculate my game time. This resulted in fluent motion of the objects, but the problem stated up top occured. After only a short time, the time I get from delta is “faster” than the one i get from the audio playback position. I then also just measured the time with my phone, and this also resulted in delta being too “fast”, and the time I get from the audio playback position to be correct.
To test, my code currently has two time variables:
- global_time, the time used to place the obstacles, uses delta
- time_elapsed_two, used as reference, uses the playback position
This is the code i am currently using for the time:
global_time += delta
time_elapsed_two = get_node("/root/Node/Music/AudioStreamPlayer").get_playback_position()
is_playing = !is_playing
And a video showcasing the problem:
the two timers represent the two variables, the bottom one is global_time (delta), the top one is time_elapsed_two(playback position)
How could I fix this problem? Are there any other ways to get the time? (normal Timer didn’t work, as they had the same offset as the delta, and getting the time over the current system time is, at least from what I read, problematic if you need to pause the time…)
Thank you (and sorry for the bad english)!