Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » on the subject of rotating an object to the bpm of a song
- doctorgabe2017
-
6 posts
on the subject of rotating an object to the bpm of a song
So, I’m having a bit of trouble with rotating the judgement line for a rhythm game that I’m making..
I’m intending for it to make a full 360° rotation around a circle with every bar of a 4/4 song, with the line making a 90° rotation every beat.
Current code:
I’m intending for it to make a full 360° rotation around a circle with every bar of a 4/4 song, with the line making a 90° rotation every beat.
Current code:
Last edited by doctorgabe2017 (June 24, 2022 09:39:49)
- 2SHSredstone
-
39 posts
on the subject of rotating an object to the bpm of a song
What kind of trouble are you having?
If your sprite is out of sync than I suggest using a current frame variable to account for lag even if frames are skipped it should still self-correct.
If your sprite is out of sync than I suggest using a current frame variable to account for lag even if frames are skipped it should still self-correct.
Last edited by 2SHSredstone (June 24, 2022 10:42:41)
- doctorgabe2017
-
6 posts
on the subject of rotating an object to the bpm of a song
I’m trying to get the sprite rotation perfectly synced to the beat What kind of trouble are you having?
If your sprite is out of sync than I suggest using a current frame variable to account for lag even if frames are skipped it should still self-correct.
- RT_Borg
-
1000+ posts
on the subject of rotating an object to the bpm of a song
Hi doctorgabe2017,
You can probably just set your direction based on the timer.
Scratch takes care of keeping the direction within its prefered angle range, so you don't have to fiddle with the angle to rotate it into the -180 to 180 range.
This will never get out of sync (unless the music doesn't play at the proper BPM) because it's based on a timer, not on keeping frames at some frame rate.
I hope this helps. Happy to answer any questions.
– RT_Borg
You can probably just set your direction based on the timer.
Scratch takes care of keeping the direction within its prefered angle range, so you don't have to fiddle with the angle to rotate it into the -180 to 180 range.
This will never get out of sync (unless the music doesn't play at the proper BPM) because it's based on a timer, not on keeping frames at some frame rate.
I hope this helps. Happy to answer any questions.
– RT_Borg
Last edited by RT_Borg (June 24, 2022 13:36:35)
- yavuz61035
-
500+ posts
on the subject of rotating an object to the bpm of a song
this somewhat works altough it gets out of sync
also, your current code doesn't work because 115/3600 is a very small number and scrstch only runs at 30fps so it's gonna wait 1 frame then turn so what you should do is change the rate it spins (like 90/sec, that's 360/4 and if you want to make it smooth you could turn it by 360/(4 * fps) (fps is basically 1/Δt (delta time), if you are wondering how to get that check out this project of mine))
also, your current code doesn't work because 115/3600 is a very small number and scrstch only runs at 30fps so it's gonna wait 1 frame then turn so what you should do is change the rate it spins (like 90/sec, that's 360/4 and if you want to make it smooth you could turn it by 360/(4 * fps) (fps is basically 1/Δt (delta time), if you are wondering how to get that check out this project of mine))
Last edited by yavuz61035 (June 24, 2022 13:35:38)
- doctorgabe2017
-
6 posts
on the subject of rotating an object to the bpm of a song
Hi doctorgabe2017,
You can probably just set your direction based on the timer.
Scratch takes care of keeping the direction within its prefered angle range, so you don't have to fiddle with the angle to rotate it into the -180 to 180 range.
This will never get out of sync (unless the music doesn't play at the proper BPM) because it's based on a timer, not on keeping frames at some frame rate.
I hope this helps. Happy to answer any questions.
– RT_Borg
Thanks, your code worked flawlessly!
(I’ll be sure to credit you for it

- Discussion Forums
- » Help with Scripts
-
» on the subject of rotating an object to the bpm of a song