Discuss Scratch

SpyLion
Scratcher
100+ posts

How to make movement smooth

So, when I try to make a platformer, all of my characters are really… not smooth.

Here is the code I used:

when [right arrow v] key pressed
move (10) steps

when that didn't work, I used:

when [right arrow v] key pressed
change x by (10)

How do I make it smooth?

Last edited by SpyLion (Dec. 21, 2022 20:41:40)

8bitrkt
Scratcher
500+ posts

How to make movement smooth

this fits better in help with scripts

this wiki article shows a step by step guide on making a smooth platformer engine.
edit: if you want a better understanding, you can use the forums or look at a more in depth youtuber tutorial or something

Last edited by 8bitrkt (Dec. 21, 2022 20:51:39)

AntonL1kesPotato
Scratcher
1000+ posts

How to make movement smooth

First, make a speed variable, set it to whatever you want. using the hat block isn't efficient, use “if key pressed” on a forever loop instead. if the arrow is pressed, set speed to 10, if it isn't, set it to speed x 0.8 (you can change this too, but 0.8 is the best imo) which now makes the movement smoother!
Here's how the code is if you didn't understand:
when green flag clicked
forever
if <key [right arrow v] pressed?> then
set [speed v] to (10)
else
set [speed v] to ((speed) * (0.8)) // if nothing is pressed, the movement gets lower
end
change x by (speed)
end
also its better to put this topic on help with scripts but whatever

Last edited by AntonL1kesPotato (Dec. 21, 2022 20:51:24)

SpyLion
Scratcher
100+ posts

How to make movement smooth

okay thanks!
donotforgetmycode
Scratcher
1000+ posts

How to make movement smooth

The events “when key pressed” block has a delay, so it's generally not a good idea to use that unless you only need to press a key once. For most things, it's better to use the sensing “key pressed?” block in a forever loop, like this:
when green flag clicked
forever
if <key [right v] pressed?> then
change x by (10)
end
if <key [left v] pressed?> then
change x by (-10)
end
end
Alternatively, you can do boolean arithmetic with operators blocks. This is harder to understand, but it's shorter:
when green flag clicked
forever
change x by ((<key [right v] pressed?> - <key [left v] pressed?>) * (10))
end

Last edited by donotforgetmycode (Dec. 21, 2022 21:23:40)

aguy165643223e
Scratcher
1 post

How to make movement smooth

i made
for the smooth movement
when [a] key pressed
repeat until <not <key [a] pressed?>>
change x by (1)
end

Last edited by aguy165643223e (Feb. 8, 2024 02:33:00)

Powered by DjangoBB