From Test-Scratch-Wiki
Movement is used to show action. It is easy to make different types of movement on scratch. Projects with movement commonly use the Change X by (), Change Y by (), and Move () Steps blocks. They are used in almost every Scratch project.
Following the Mouse
It is easy to script an object following the mouse. It is commonly used for top down games. It looks best to set the rotation style to "Full rotation".
when gf clicked // Starts the script. forever // Makes it so the movement will keep going. point towards [mouse-pointer v] // Aims for the mouse. move (10) steps // Moves.
Top-Down Arrow Keys movement
This engine gives the player more control over where they move. It is an alternative to the mouse following engine.
when gf clicked // Starts the script. forever // Allows movement to be repeated. if <key [up arrow v] pressed> then // Detects an input. change y by (5) // Moves in the wanted direction. end // (Same goes for the rest.) if <key [down arrow v] pressed> then change y by (-5) end if <key [right arrow v] pressed> then change x by (5) end if <key [left arrow v] pressed> then change x by (-5) end
Velocity Movement
A more detailed version of the others. This works from a sideways platformer perspective.
when gf clicked // Starts the script. forever // Allows movement to be repeated. if <key [right arrow v] pressed> then // Detects an input. change [X Velocity v] by (1) // Moves in the wanted direction. end // (Same goes for left movement.) if <key [left arrow v] pressed> then change [X Velocity v] by (-1) end // set [X Velocity v] to ((X Velocity) * (0.9)) // Slowly slows down speed. change x by (X Velocity) // Makes the sprite move.