Discuss Scratch

HappyKid54321
Scratcher
100+ posts

Smooth rotation

So I'm making a sprite where it spins around when left and right arrow keys are pressed. So i'm using this code:
when [Left arrow v] key pressed
turn ccw (3) degrees
and,
when [Right arrow v] key pressed
turn cw (3) degrees
But when I use it, there is like a 0.25 second delay between each time it rotates.
So I need a smooth version of what code is on top.
Thanks so much if you can find this out
knightjj11
Scratcher
100+ posts

Smooth rotation

If you're experiencing a delay between each rotation when using the arrow keys in Scratch, it might be due to the default “key repeats” settings in the Scratch editor. Fortunately, you can adjust these settings to achieve smoother rotations.

Here's how you can make it smoother:

Click on the “Stage” to select it.
Look for the “Stage” backdrop's code area.
Add the following code:

when green flag clicked
forever
if <key [put whatever here] pressed?> then
turn ccw (3) degrees

end
end

This code continuously checks if the left or right arrow key is pressed and then turns the sprite accordingly. By placing this code in the backdrop, you avoid the default key repeat settings and can achieve smoother rotations.

Now, when you press and hold the left or right arrow key, the sprite should smoothly rotate without the delay you experienced before. Adjust the degree values if you want a faster or slower rotation speed.

- Jason a.k.a Knightjj11
RokCoder
Scratcher
1000+ posts

Smooth rotation

The answer above is partially right but also quite confusing.

When you press a key and hold it down there is a slight delay before the key repeats. You can see this when typing a comment into the forum. It's the default behaviour for a computer keyboard. This is what you see when using the when (any) key pressed blocks. If you want to react smoothly to key presses without this initial pause after the first press, use the key (any) pressed? blocks as described above. Don't use them in the stage though - use them in the sprite that is reacting to the key presses.
alebro6DW
Scratcher
100+ posts

Smooth rotation

knightjj11 wrote:

If you're experiencing a delay between each rotation when using the arrow keys in Scratch, it might be due to the default “key repeats” settings in the Scratch editor. Fortunately, you can adjust these settings to achieve smoother rotations.

Here's how you can make it smoother:

Click on the “Stage” to select it.
Look for the “Stage” backdrop's code area.
Add the following code:

when green flag clicked
forever
if <key [put whatever here] pressed?> then
turn ccw (3) degrees

end
end

This code continuously checks if the left or right arrow key is pressed and then turns the sprite accordingly. By placing this code in the backdrop, you avoid the default key repeat settings and can achieve smoother rotations.

Now, when you press and hold the left or right arrow key, the sprite should smoothly rotate without the delay you experienced before. Adjust the degree values if you want a faster or slower rotation speed.

- Jason a.k.a Knightjj11
Motion blocks don't work in the stage.
HappyKid54321
Scratcher
100+ posts

Smooth rotation

Thanks guys this works!
Ereasercollector2
Scratcher
7 posts

Smooth rotation

Could this help?

when green flag clicked
reset timer
point in direction (90)
forever
repeat (Put whatever here)
turn cw ([sin v] of (timer)::operators) degrees
end
wait (0.5) secs
reset timer
repeat (Put whatever here)
turn ccw ([sin v] of (timer )::operators) degrees
end
wait (0.5) secs
reset timer
end

Hope it helps!

Last edited by Ereasercollector2 (Jan. 3, 2025 13:59:15)

Ereasercollector2
Scratcher
7 posts

Smooth rotation

Ereasercollector2 wrote:

Could this help?

when green flag clicked
reset timer
point in direction (90)
forever
repeat (Put whatever here)
turn cw ([sin v] of (timer)::operators) degrees
end
wait (0.5) secs
reset timer
repeat (Put whatever here)
turn ccw ([sin v] of (timer )::operators) degrees
end
wait (0.5) secs
reset timer
end

Hope it helps!

Powered by DjangoBB