Discuss Scratch

nickninjanutjobYT
Scratcher
19 posts

how to make smooth movement for a scratch platformer

i already have a script for it heres the project so far

its just really clunky

https://scratch.mit.edu/projects/1069561350/

Last edited by nickninjanutjobYT (Sept. 18, 2024 18:05:05)

bsteichman
Scratcher
500+ posts

how to make smooth movement for a scratch platformer

in your movement script you have a wait block, I would remove that. after removing it, if it is too fast for you, simply decrease how much it changes by X. Don't quote me on this, but I'm pretty sure that using a wait block cuts the framerate (30fps) in half, because it takes one frame to wait, and another to move the slime.

Last edited by bsteichman (Sept. 18, 2024 18:21:34)

Scratch137
Scratcher
1000+ posts

how to make smooth movement for a scratch platformer

For smoother left-right movement, you'll want to use a velocity system.
I can see that you've tried to implement a “momentum” system into your game; this doesn't work particularly well for several reasons.
  1. There is a “wait 0.05 seconds” block slowing the movement down.
  2. The movement speed is set to a minimum of 6 pixels per frame (1.5 * 4 = 6), and the acceleration is so low that the speed change is hardly noticeable.
  3. The script stops running as soon as you release the movement key, so the player cannot slow down organically.
  4. You are using separate momentum variables for rightward and leftward movement, so the two values end up fighting.
To solve these problems, first create a “velocity” variable and change your script to have it modify the velocity rather than changing the player's position directly. A positive velocity means that the sprite is moving right, and a negative velocity means it is moving left.

when green flag clicked
forever
if <key [d v] pressed?> then //moving right
change [velocity v] by (2.5)
end
if <key [a v] pressed?> then //moving left
change [velocity v] by (-2.5)
end
set [velocity v] to ((velocity) * (0.8)

The “set velocity to velocity * 0.8” block at the end serves three main functions:
  1. Affects how quickly the sprite speeds up and slows down
  2. Gives the sprite a maximum speed (10, in this case)
  3. Makes the sprite slow down when not pressing A or D
Without this, the sprite would just move forever.

Finally, we can make the sprite actually move. To do this, add a script that constantly changes the player's x position by their velocity.

when green flag clicked
forever
change x by (velocity)

This code should work for your project; the values I used above achieve roughly the same movement speed as before.
Of course, you can modify these to your liking; just keep in mind that the last value (“set velocity to velocity * 0.8”) must be a number between 0 and 1.

By the way… I noticed that the “block” sprite you're using to create the ground clones itself infinitely, even after it's already filled the screen.
This causes it to quickly hit the 300 clone limit, preventing any more clones from being created.
To avoid this, you should only create as many clones as you need to fill the screen, and then stop. 10 clones seems to do the trick.

when I receive [generate v]
repeat (10)
create clone of [myself v]
change x by (50)

Last edited by Scratch137 (Sept. 18, 2024 19:44:00)

nickninjanutjobYT
Scratcher
19 posts

how to make smooth movement for a scratch platformer

tysm
nickninjanutjobYT
Scratcher
19 posts

how to make smooth movement for a scratch platformer

anyway u could help me make a better jump system???
nickninjanutjobYT
Scratcher
19 posts

how to make smooth movement for a scratch platformer

and I also need some help making a side scrolling system
s714655
Scratcher
100+ posts

how to make smooth movement for a scratch platformer

nickninjanutjobYT wrote:

and I also need some help making a side scrolling system
I can make a sample project for you if you want…
GENTLEMANNEofLEISURE
Scratcher
31 posts

how to make smooth movement for a scratch platformer

nickninjanutjobYT wrote:

anyway u could help me make a better jump system???
here is probably janky untested script
when green flag clicked
set [yvelocity v] to [0]
forever
change [yvelocity v] by ((0)- <not <touching [level v] ?>>)
set [yvelocity v] to ((yvelocity) * (.9))
change y by (yvelocity)
if <touching [level v] ?> then
change y by ((0) - (yvelocity))
set [yvelocity v] to (0)
end
if <<key [space v] pressed?> and <touching [level v] ?>> then
set [yvelocity v] to (16)
change y by (yvelocity)
end
end
s714655
Scratcher
100+ posts

how to make smooth movement for a scratch platformer

s714655 wrote:

nickninjanutjobYT wrote:

and I also need some help making a side scrolling system
I can make a sample project for you if you want…
finished https://scratch.mit.edu/projects/1069982870/

Last edited by s714655 (Sept. 19, 2024 14:03:22)

brokendudethefirst
Scratcher
2 posts

how to make smooth movement for a scratch platformer

you could also do this simple easier method its not the best but you cant really
tell when your moving. i am a first time scratch poster so i dont know how to do blocks sorry> :0
when [ space] key pressed
change y by (10)
[scratchblock
repeat (12 )

end
repeat the same thing but with a wait block in the middle and a -10
wait () secs

repeat (12)

end

change y by (10)


add everything together to get the jump here is also a demonstration of ithere]

Last edited by brokendudethefirst (Feb. 19, 2025 14:59:24)

awsome_360
Scratcher
1 post

how to make smooth movement for a scratch platformer

when green flag clicked
go to x: (0) y: (0)
set [Y] to [0]
forever
change [Y] by (-1)
change y by (Y)
end

Powered by DjangoBB