411 REFERENCE · Wikibooks
Scratch Virtual Machine/Blocks/Motion
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Motion blocks affect the position and direction of a sprite.scratch3_motion.js https://github.com/scratchfoundation/scratch-editor/blob/6fd95da6340916c2693452e012b52fbd13f19c50/packages/scratch-vm/src/blocks/scratch3_motion.js 2026-08-02 Scratch Foundation en GitHub
move (STEPS) steps
Moves the sprite STEPS forward in the direction it is facing.
Casts STEPS to a number. (STEPS)
Subtracts the target's direction from 90 and converts it to radians. (RADIANS)
setXY(the target's X position plus STEPS multiplied by the cosine of RADIANS, the target's Y position plus STEPS multiplied by the sine of RADIANS)
motion_movesteps(STEPS):
STEPS = castToNumber(STEPS)
RADIANS = degreesToRadians(90 - target.direction)
setXY(target.x + STEPS * cos(RADIANS), target.y + STEPS * sin(RADIANS))
turn ⟳ clockwise, right (DEGREES) degrees
Rotates the sprite clockwise DEGREES degrees.
Casts DEGREES to a number. (DEGREES)
setDirection(the target's direction added to DEGREES)
motion_turnright(DEGREES):
DEGREES = castToNumber(DEGREES)
setDirection(target.direction + DEGREES)
turn ⟲ counterclockwise, left (DEGREES) degrees
Rotates the sprite counterclockwise DEGREES degrees.
Casts DEGREES to a number. (DEGREES)
setDirection(the target's direction subtracted by DEGREES)
motion_turnleft(DEGREES):
DEGREES = castToNumber(DEGREES)
setDirection(target.direction - DEGREES)
go to (TO)
Moves the sprite to a particular set of X and Y coordinates as determined by TO.
getTargetXY(TO) (X, Y)
setXY(X, Y)
motion_goto(TO):
X, Y = getTargetXY(TO)
setXY(X, Y)
go to x: (X) y: (Y)
Moves the sprite to the given X and Y coordinates.
Casts X to a number. (X)
Casts Y to a number. (Y)
setXY(X, Y)
motion_gotoxy(X, Y):
X = castToNumber(X)
Y = castToNumber(Y)
setXY(X, Y)
glide (SECS) secs to (TO)
Linearly transitions the sprite to a particular set of X and Y coordinates as determined by TO over a SECS second period.
getTargetXY(TO) (X, Y)
glide(SECS, X, Y)
motion_glideto(SECS, TO):
X, Y = getTargetXY(TO)
motion_glidesecstoxy(SECS, X, Y)
glide (SECS) secs to x: (X) y: (Y)
Linearly transitions the sprite to the given X and Y coordinates over a SECS second period.
Explain how glide works.motion_glidesecstoxy(SECS, X, Y):
...
point in direction (DIRECTION)
Rotates the sprite such that it faces the given DIRECTION in degrees.
Casts DIRECTION to a number. (DIRECTION)
setDirection(DIRECTION)
motion_pointindirection(DIRECTION):
DIRECTION = castToNumber(DIRECTION)
setDirection(DIRECTION)
point towards (TOWARDS)
Rotates the sprite such that it faces a particular direction as determined by TOWARDS.
If TOWARDS is the string _mouse_:
Subtracts the target's X position from the X position of the mouse-pointer. (DX)
Subtracts the target's Y position from the Y position of the mouse-pointer. (DY)
Converts the 2-argument arctangent of DY and DX in radians to degrees. (DIRECTION)
setDirection(DIRECTION)
Otherwise, if TOWARDS is the string _random_:
setDirection(a random integer on the interval [-180, 180], with -180 and 180 being twice as unlikely as other values)
Otherwise:
Casts TOWARDS to a string. (TOWARDS)
Finds the sprite by the name of TOWARDS. (SPRITE)
If SPRITE exists:
Subtracts the target's X position from SPRITE's X position. (DX)
Subtracts the target's Y position from SPRITE's Y position. (DY)
Converts the 2-argument arctangent of DY and DX in radians to degrees. (DIRECTION)
setDirection(DIRECTION)
Otherwise, does nothing.
motion_pointtowards(TOWARDS):
if TOWARDS is "_mouse_"
DX = mouse.x - target.x
DY = mouse.y - target.y
DIRECTION = radiansToDegrees(atan2(DY, DX))
setDirection(DIRECTION)
else if TOWARDS is "_random_"
setDirection(round(random() * 360) - 180)
else
TOWARDS = castToString(TOWARDS)
SPRITE = getSpriteNamed(TOWARDS)
if SPRITE exists
DX = SPRITE.x - target.x
DY = SPRITE.y - target.y
DIRECTION = radiansToDegrees(atan2(DY, DX))
setDirection(DIRECTION)
else
(do nothing)
change x by (DX)
Increases the target's X position by DX.
Casts DX to a number. (DX)
setXY(DX added to the target's X position, the target's Y position)
motion_changexby(DX):
DX = castToNumber(DX)
setXY(target.x + DX, target.y)
set x to (X)
Sets the target's X position to X.
Casts X to a number. (X)
setXY(X, the target's Y position)
motion_setx(X):
X = castToNumber(X)
setXY(X, target.y)
change y by (DY)
Increases the target's Y position by DY.
Casts DY to a number. (DY)
setXY(the target's X position, DY added to the target's Y position)
motion_changeyby(DY):
DY = castToNumber(DY)
setXY(target.x, target.y + DY)
set y to (Y)
Sets the target's Y position to Y.
Casts Y to a number. (Y)
setXY(the target's X position, Y)
motion_sety(Y):
Y = castToNumber(Y)
setXY(target.x, Y)
if on edge, bounce
Explain how if on edge, bounce works.motion_ifonedgebounce():
...
set rotation style (STYLE)
Sets the target's rotation style as determined by STYLE.
If STYLE is one of the strings don't rotate, all around, or left-right, sets the target's rotation style to STYLE.
If the sprite is visible, requests to redraw the screen.
motion_setrotationstyle(STYLE):
if STYLE is "don't rotate" or is "all around" or is "left-right"
target.rotationStyle = STYLE
if target.visible
redraw()
x position
Reports the target's X position.
If the target's X position is less than 1e-9 away from the nearest integer:
Reports the target's X position rounded to the nearest integer.
Otherwise:
Reports the target's X position.
motion_xposition():
if abs(target.x - round(target.x)) < 1e-9
return round(target.x)
else
return target.x
y position
Reports the target's Y position.
If the target's Y position is less than 1e-9 away from the nearest integer:
Reports the target's Y position rounded to the nearest integer.
Otherwise:
Reports the target's Y position.
motion_yposition():
if abs(target.y - round(target.y)) < 1e-9
return round(target.y)
else
return target.y
direction
Reports the target's direction.
Reports the target's direction in degrees.
motion_direction():
return target.direction
scroll right ()
Does nothing. This is a legacy block retained for backwards compatibility with Scratch 2.0 and is not visible in the block palette.
motion_scroll_right():
(do nothing)
scroll up ()
Does nothing. This is a legacy block retained for backwards compatibility with Scratch 2.0 and is not visible in the block palette.
motion_scroll_up():
(do nothing)
align scene ()
Does nothing. This is a legacy block retained for backwards compatibility with Scratch 2.0 and is not visible in the block palette.
motion_align_scene():
(do nothing)
x scroll
Reports undefined. This is a legacy block retained for backwards compatibility with Scratch 2.0 and is not visible in the block palette.
motion_xscroll():
return undefined
y scroll
Reports undefined. This is a legacy block retained for backwards compatibility with Scratch 2.0 and is not visible in the block palette.
motion_yscroll():
return undefined
References