Skip to content

motion

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);
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 arguments
motion.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.

motion.point(degrees: num) -> void
motion.point(target: Target | str) -> void
motion.point(90); # right
motion.point(0); # up
motion.point(-90); # left
motion.point(180); # down
motion.point("_mouse_");
motion.point(motion.Target.MOUSE); # identical
motion.point("Apple"); # another sprite

The overloads resolve on the argument type, so a num picks motion_pointindirection and a string picks motion_pointtowards.

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);
motion.ifOnEdgeBounce() -> void
motion.setRotationStyle(style: RotationStyle) ✅
motion.setRotationStyle(motion.RotationStyle.LEFT_RIGHT);
motion.setRotationStyle("left-right"); # identical

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");

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"