motion
Moving
Section titled “Moving”motion.forward(steps: num) -> void ✅ # "move () steps"motion.turn(degrees: num) -> void ✅ # "turn right () degrees"Turn left by turning a negative amount:
motion.forward(100);motion.turn(90);motion.turn(-90);Going to a position
Section titled “Going to a position”motion.goTo(x: num, y: num) -> void ✅motion.goTo(position: Target | str) -> void ✅motion.glideTo(time: num, x: num, y: num) -> void ✅motion.glideTo(time: num, position: Target | str) ✅motion.goTo(0, 0);motion.goTo("_random_");motion.goTo(y = 0, x = 0); # named argumentsmotion.glideTo(1, 100, 50);motion.glideTo(1, "_random_");Target strings: "_random_", "_mouse_", or a sprite’s name. This menu also lists sprite
names, so the parameter keeps its | str arm and takes a computed name too.
Pointing
Section titled “Pointing”motion.point(degrees: num) -> void ✅motion.point(target: Target | str) -> void ✅motion.point(90); # rightmotion.point(0); # upmotion.point(-90); # leftmotion.point(180); # down
motion.point("_mouse_");motion.point(motion.Target.MOUSE); # identicalmotion.point("Apple"); # another spriteThe overloads resolve on the argument type, so a num picks
motion_pointindirection and a string picks motion_pointtowards.
Changing x and y
Section titled “Changing x and y”motion.changeX(dX: num) -> void ✅motion.setX(x: num) -> void ✅motion.changeY(dY: num) -> void ✅motion.setY(y: num) -> void ✅motion.changeY(5);motion.setX(0);Edges and rotation
Section titled “Edges and rotation”motion.ifOnEdgeBounce() -> void ✅motion.setRotationStyle(style: RotationStyle) ✅motion.setRotationStyle(motion.RotationStyle.LEFT_RIGHT);motion.setRotationStyle("left-right"); # identicalNot available
Section titled “Not available”Reading position. There is no motion.x() or motion.y() reporter in the stdlib, and
motion.getPosition() resolves to katnip_motion_position, which has no codegen.
The underlying Scratch blocks do have codegen metadata, so bind them yourself:
proc x(@opcode = "motion_xposition") -> num {}proc y(@opcode = "motion_yposition") -> num {}
proc drift() -> void { if (x() > 200) { motion.setX(-200); }}To read another sprite’s position, go through sensing:
temp cx: num = sensing.getProperty("x position", "Cat");Full enum reference
Section titled “Full enum reference”Reference a member through the namespace (motion.Target.RANDOM), or pass the value as a
literal — both compile to the same block.
motion.Target |
Value |
|---|---|
RANDOM |
"_random_" |
MOUSE |
"_mouse_" |
motion.RotationStyle |
Value |
|---|---|
LEFT_RIGHT |
"left-right" |
ALL_AROUND |
"all around" |
NONE |
"don't rotate" |