Discuss Scratch

12artem12
Scratcher
14 posts

How to make smooth rotation?

I want to make a sprite rotating, and I want so when I press a button the rotation speed increases and when i release - decreases. I made the same thing with movement, but I can't do it with rotation though.
Mandale_county_333
Scratcher
7 posts

How to make smooth rotation?

Is there already existing code?
ProfessorUelf
Scratcher
100+ posts

How to make smooth rotation?

12artem12
Scratcher
14 posts

How to make smooth rotation?

Is there already existing code?
Yea, but it's as simple as

when green flag clicked
forever
if <key [up arrow v] pressed?> then
change [speed v] by (1)
end
if <not <key [up arrow v] pressed?>> then
change [speed v] by (-1)
end
end
when green flag clicked
forever
if <<(speed) = [0]> or <(speed) < [0]> then
set [speed v] to [0]
end
if <<(speed) = [21]> or <(speed) > [0]> then
set [speed v] to [21]
end
end
idk why the if blocks turned red

Last edited by 12artem12 (Yesterday 14:23:38)

12artem12
Scratcher
14 posts

How to make smooth rotation?

ProfessorUelf wrote:

This should help:

https://scratch-mit-edu.ezproxyberklee.flo.org/projects/733613064
This is great, but not what I needed. I want to rotate the sprite with buttons only.
ProfessorUelf
Scratcher
100+ posts

How to make smooth rotation?

So should it just turn up when pressing up, or start to rotate faster and faster?
12artem12
Scratcher
14 posts

How to make smooth rotation?

ProfessorUelf wrote:

So should it just turn up when pressing up, or start to rotate faster and faster?
It should accelerate when the button is pressed to a certain limit, and when you release the button, on the contrary, it should slow down to zero.
grandpasp2
Scratcher
12 posts

How to make smooth rotation?

Scratch_builder3000
Scratcher
14 posts

How to make smooth rotation?

Try this! 10 is the limit, and 30 is how fast it reaches the limit - the lower the number, the faster it is.

when green flag clicked
go to x:(0) y:(0)
point in direction (90)
set [Increment v] to (0)
when [space v] key pressed
repeat until <not <key (space v) pressed?>>
change [Increment v] by (((Increment)+(1))/(30))
if <(10)>(Increment)> then
turn right (Increment) degrees
else
set [Increment v] to (10)
turn right (Increment) degrees
end

//if you want it to also gradually slow down, plug this AFTER the repeat until script!

repeat until <(0.5)>(Increment)>
change [Increment v] by (((Increment)+(1))/(-30))
turn right (Increment) degrees
end
set [Increment v] to (0)

Powered by DjangoBB