Please expand this article. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021)
A sprite moving, visualized via Sprite trails

Movement is the action of changing an object's position. It is used to show action. Scratch provides various blocks that can be used to create movement, including the change x by (), change y by (), and move () steps blocks; these blocks can be found in the Motion category.

Following the Mouse

This script can be used to make a sprite follow the mouse-pointer.

when gf clicked // starts the script
forever // repeats the movement until the stop sign is clicked
point towards (mouse-pointer v) // aims for the mouse
move (10) steps // moves towards the mouse

You can also use the following script to make a sprite follow the mouse-pointer but stay in a 90-degree direction.

when gf clicked//starts the script
forever//this makes sure that the sprite keeps moving
go to (mouse-pointer v) // moves sprite to the mouse-pointer

This script can be used for smoother movement:

when gf clicked
forever
point towards (mouse-pointer v)
move ((distance to (mouse-pointer v)) / [5]) steps // Without the (()-()) block, the sprite would go straight to the mouse-pointer.

Arrow Keys Movement

This script gives more control over the movement, and it uses the arrow keys rather than the mouse. However, this script only allows for movement horizontally and vertically.

when green flag clicked
forever
    if <key (up arrow v) pressed?> then 
        change y by (1)
    end
    if <key (down arrow v) pressed?> then
        change y by (-1)
    end
    if <key (right arrow v) pressed?> then
        change x by (1)
    end
    if <key (left arrow v) pressed?> then
        change x by (-1)
    end


These scripts also can be simplified by using boolean conditions in the []-[] block.

when green flag clicked
forever
change x by ((<key (right arrow v) pressed?> - <key (left arrow v) pressed?>) * (10))
change y by ((<key (up arrow v) pressed?> - <key (down arrow v) pressed?>) * (10))

Alternatively, the When key pressed block can also be used:

when [up arrow v] key pressed // if key is pressed
change y by (10) // move in wanted direction
when [down arrow v] key pressed
change y by (-10)
when [right arrow v] key pressed
change x by (10)
when [left arrow v] key pressed
change x by (-10)

However, this has the limitation of requiring the player to hold the key for some time before moving continuously.

Velocity Movement

This script creates a smoother form of movement. It works by gradually increasing or decreasing the amount that the sprite moves each loop through the use of a variable.

when gf clicked // starts the script
forever // loops the movement script
if <key (right arrow v) pressed> then // detects an input
change [x velocity v] by (1) // changes the velocity variable
end
if <key (left arrow v) pressed> then
change [x velocity v] by (-1)
end
set [x velocity v] to ((x velocity) * (0.9)) // Slowly decreases velocity. 0.9 can be replaced with any value between 0 and 1 - the smaller it is, the faster the sprite stops.
change x by (x velocity) // makes the sprite move based on the velocity variable

See Also