• 2D
  • BPM by rotation of a sprite not consistent

Good morning / afternoon / evening for the people reading the question..

I started using Godot since a couple days, gone through some tutorials and tried making a rhythm game, where you interact with the application at a specific time. Used tweens to animate rotation 360 degrees per one beat (i.e. 60 BPM =360 deg/1 sec , 120 BPM = 360 deg/0.5 sec, N BPM = 360 deg / 60/N). By making the tweens interpolate property of the sprite's rotation determined by BPM, the function itself seemed to work out well..

Here's where the main problems initiates Since rhythm games are strict with beats: lags and its inconsistency affect the play a lot, which is now happening. Everything works with proper equations theoretically, but probably reality hates me to apply those logics..

I would be so happy if I can get helped :D

Here is the code how I found the inconsistency:

BPM Tick function: func _process(delta): if Hand.rotation_degrees == float(0): $Hand/SFX.play();

Function: Whenever the degree is 0, play a sound effect allocated at $Hand/SFX

func _startAnimation(bpm): tween.interpolate_property(Hand, "rotation_degrees", Hand.rotation_degrees, Hand.rotation_degrees + 360, float(time), Tween.TRANS_LINEAR, Tween.EASE_IN) tween.start();

How it works

P.S. I accidentally hit enter whilst editing, my bad :sweat_smile: The _startAnimation(bpm) rotates the hand by 360 in the assigned time..

Welcome to the forums @Adminator!

I have not tried the code myself, but Godot has a page on the documentation for syncing audio and gameplay together that may be helpful to look at. It looks like it uses information from the AudioServer to compensate for lag and delays between audio playback, which I think is what is happening in your project currently (if I understand correctly).

@TwistedTwigleg Thank you for the reply! The document was helping for compensation.. Except the point that the click is played when the needle (Hand as variable) reaches 0 degrees, and when I compared with the metronome in FL Studio it was found that the tick was going slower and slower and losing the sync. Any other ways that I can try? Probably ticking by subdividing delta would work?

Great! I'm glad the document was helpful.

Any other ways that I can try? Probably ticking by subdividing delta would work?

I'm not sure, to be honest. You could look at the documentation for the AudioServer, maybe there is something that can help. Another thing you could look at this project from GDQuest that implements a 2D rhythm game and see if there is something there they are using to work around the issue.

Thank you for the recommendation! I'm so glad I can reach help when I need help :D