NEW Explore the Scratch Block Dictionary, tutorials, textbook, and classroom guides

Start learning →

distance to (mouse-pointer / Sprite) — Scratch Block Guide

📌 What you will learn

Returns the straight-line pixel distance between this sprite’s center and the target.

What this block does

Returns the straight-line pixel distance between this sprite’s center and the target.

Trigger enemy aggro when within 120 pixels or calculate circular hit detection.

  • Category: Sensing Blocks
  • Key tip: Much faster than pixel-perfect collision for circular objects like planets or explosions.

Working Scratch example

Try building this small script in the Scratch editor, predict what will happen, then click the green flag to test it.

Example using distance to (mouse-pointer / Sprite)
  1. When green flag clicked
  2. Forever
  3. If <(distance to Player) (120) then
  4. Point towards Player
  5. Move 3 steps

Try it: Enemy wakes up and chases the player when they get close.

Related block guides

Explore other blocks in the same category or return to the full English Block Dictionary.

Back to Sensing Blocks See the overview and patterns for Sensing Blocks. Learn more → Scratch Block Dictionary (All Categories) Browse Motion, Looks, Sound, Events, Control, Sensing, Operators, Variables, and Extensions. Learn more →

FAQ

When should I use "distance to (mouse-pointer / Sprite)" in Scratch?

Trigger enemy aggro when within 120 pixels or calculate circular hit detection. Much faster than pixel-perfect collision for circular objects like planets or explosions.

This guide is provided for educational purposes. Scratch screens and terms may change over time, so please check the official Scratch website as well.