Chapter 4

Motion Blocks

Motion blocks are used to rotate the sprite and to move it around the stage.

Subsections of Motion Blocks

introduction

The motion blocks control the motion of the sprite across the stage. In working with these blocks, it is important to remember the coordinate system Scratch uses, which is based on Cartesian coordinates. These consist of two coordinates, the first is along the x-axis (horizontal), and the second along the y-axis (vertical). The boundary of the stage is from -240 to 240 on the x-axis, and -180 to 180 on the y-axis. This can be seen in the image below:

Scratch Coordinate System Scratch Coordinate System

Sprites are allowed to move anywhere on the stage, but cannot move off it (if you want your sprite to disappear off-stage, use the hide block from the Looks palette). Attempting to change a coordinate to a value off-stage will instead set it to the maximum/minimum value.

In addition to specifying movement using coordinates, sprites can also be moved forward. Each sprite has a direction it is facing, measured as an angle between 0 and 360 degrees. The angle 0 is straight up, and positive rotations are clockwise. Rather than specifying positive and negative rotations on blocks, Scratch uses a clockwise and counterclockwise arrow to indicate a change in direction.

Info

While Scratch adopts the familiar Cartesian coordinate system from mathematics, it does not adopt the unit circle (with the angle 0 aligning with the postive x-axis and positive rotations in a counter-clockwise direction). Instead it adopts clockface-based angles, with 0 degrees corresponding to 12-o’clock position, and positive rotation matching in the direction of clock hand movement.

move () steps

move () steps block move () steps block

The move () steps blocks moves a sprite in the direction it is currently facing. Each step corresponds to one unit on the stage.

Notes

  • The movement of this block is immediate. If you want the movement to be animated over time, use a glide block or repeat the move () steps alternated with a wait () seconds block. See the animated movement design pattern for details.
  • The direction of the sprite may not correspond with the artwork of the sprite. For example, Scratch cat is drawn facing to the left (90 degrees).
  • If the block would move the sprite off-screen in one of the two coordinates, it will stop moving in that direction while still moving in the other. This causes the sprite to appear to “slide” along the edge of the screen.

turn clockwise () degrees

turn clockwise () degrees block turn clockwise () degrees block

The turn clockwise () degrees rotates the sprite in a clockwise direction by the specified number of degrees.

Notes

  • In Scratch, the positive direction of rotation is clockwise
  • In Scratch, and angle of 0 is straight up
  • A Sprite’s appearance and direction may not correspond if it’s costume was not drawn facing upwards

turn counterclockwise () degrees

turn counterclockwise () degrees block turn counterclockwise () degrees block

The turn counterclockwise () rotates the sprite in a counterclockwise direction by the specified number of degrees.

Notes

  • In Scratch, the positive direction of rotation is clockwise
  • In Scratch, and angle of 0 is straight up
  • A Sprite’s appearance and direction may not correspond if it’s costume was not drawn facing upwards

go to ()

go to go to

The go to () block moves the sprite to the specified location. Possible locations include:

  • random position - randomly chosen coordinates on-stage
  • mouse pointer - the locationof the mouse cursor at the moment the block is executed
  • The position of other sprites in the project at the moment the block is executed

Notes

  • The movement is instantaneous.
  • The names of other sprites only appear in the list after they have been added to the project
  • When a sprite is chosen as the target, the position used is always that of the original sprite, not one of its clones

go to x: () y: ()

go to x: () y: () block go to x: () y: () block

The go to x: () y: () block moves a sprite to the coordinates (x, y) provided they are on the stage.

Notes

  • The movement is instantaneous. If you would like it to be animated over time, see the glide () secs to x: () y:() block.
  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to move a sprite to (6,300) would instead place it at (6, 180). The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

glide () secs to ()

go to go to

The glide () secs to () block moves the sprite to the specified location over the specified number of seconds. Possible locations include:

  • random position - randomly chosen coordinates on-stage
  • mouse pointer - the location of the mouse cursor at the moment this block is executed
  • The position of other sprites in the project at the moment this block is executed

Notes

  • The names of other sprites only appear in the list after they have been added to the project
  • When a sprite is chosen as the target, the position used is always that of the original sprite, not one of its clones

glide () secs to x: () y: ()

glide () secs to x: () y: () block glide () secs to x: () y: () block

The glide to x: () y: () block moves a sprite to the coordinates (x, y) over the specified number of seconds, provided the coordinates are on the stage.

Notes

  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to move a sprite to (6,300) would instead place it at (6, 180). The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

change x by ()

change x by block change x by block

The change x by () block changes the sprites x-coordinate by the supplied value. For example, if the sprite was currently at x: 110, and the value of 10 was supplied to this block, the new value would be x: 120.

Notes

  • The movement is instantaneous.
  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to change a sprite’s x position by 600 would instead set its x position to 240. The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

set x to ()

set x to () block set x to () block

The set x to block changes the sprite’s x position to the provided value.

Notes

  • The movement is instantaneous.
  • If you want to set both the x and y coordinates at the same time, use go to x: () y: () instead.
  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to set x to -300 would instead set it to -240. The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

change y by ()

change y by block change y by block

The change y by () block changes the sprites y-coordinate by the supplied value. For example, if the sprite was currently at y: 130, and the value of -10 was supplied to this block, the new value would be x: 120.

Notes

  • The movement is instantaneous.
  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to change a sprite’s y position by -400 would instead set its y position to -180. The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

set y to ()

set x to () block set x to () block

The set y to block changes the sprite’s y position to the provided value.

Notes

  • The movement is instantaneous.
  • If you want to set both the x and y coordinates at the same time, use go to x: () y: () instead.
  • If the desired position has off-stage coordinates these will be clamped to the max/min allowable coordinate to keep the sprite on-stage. I.e. attempting to set y to 250 would instead set it to 180. The coordinate system for the stage is:

Scratch Coordinate System Scratch Coordinate System

x position

x position block x position block

The x position block reports a sprite’s current x coordinate on the stage.

Notes

  • The value can be displayed on the stage by checking the box next to the block in the code palette
  • The value displayed on the stage is always that of the original sprite
  • When used in a script run by a clone, it refers to the clone’s position

x position

y position block y position block

The y position block reports a sprite’s current y coordinate on the stage.

Notes

  • The value can be displayed on the stage by checking the box next to the block in the code palette
  • The value displayed on the stage is always that of the original sprite
  • When used in a script run by a clone, it refers to the clone’s position

direction

direction block direction block

The direction block reports a sprite’s current direction, an angle between -180 and +180 degrees.

Notes

  • Setting an angle larger or smaller than the bounds will wrap (i.e. 185 will become -175)
  • The value can be displayed on the stage by checking the box next to the block in the code palette
  • The value displayed on the stage is always that of the original sprite
  • When used in a script run by a clone, it refers to the clone’s position