Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding a Loot Table, Spawn Rule & Crafting Recipe
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Constant Effects
      Scripts
    • Avoiding State Limit
    • Fake Blocks
      Scripts
    • Ore Loot Tables
      Scripts
    • Precise Interaction
      Scripts
    • Precise Rotation
      Scripts
    • Rotatable Blocks
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Vanilla Block Models
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • NBT Commands
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
    • On First World Load
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Techniques
    • Execute Logic Gates
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Custom Crafter
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Emojis & Symbols
  • Molang
  • Namespaces
  • Overwriting Assets
  • Raw Text
  • Shaders
  • Sounds
  • Subpacks
  • Text and Localization
  • Texture Atlases
  • textures_list.json
Documentation
  • Shared Constructs
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Menu Categories
  • Molang Queries
  • Pack Folder Structure
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogues
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Flying Entities
    • Introduction to AOE Clouds
    • Invulnerable Entities
    • Look at Entity
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • High Resolution Items
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Identifiers
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Experiments in Minecraft Education
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Block Placement Prevention
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Requests API
    • Simple Chat Commands
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Movement Detections

Movement Detections
  • Introduction
  • is_moving
  • Differentiating Walking And Sprinting
  • is_sleeping
  • is_sneaking
  • is_crawling
  • Differentiating Crawling, Gliding And Swimming
  • Folder Structure

Introduction ​

Sourced by the Bedrock Commands Community (BCC) Discord

Image Credits: Unofficial Minecraft Wiki - CC BY-NC-SA 3.0

These command-techniques allow you to detect certain player/entity 'states' and subsequently execute your desired commands.

Note: For a more performant and high-accuracy approach, it is advisable to use Animation Controllers

is_moving ​

This technique allows you to detect when your target is/isn't moving, accounting for even subtle movements.

Known Issues:

  1. Does not account for movement while the spyglass is zoomed in or when Slowness Level 6 or higher is in effect.
  2. Jumping causes the detection to trigger twice.

Commands:

  • Make sure you add the wiki:q.is_moving scoreboard objective:
    • /scoreboard objectives add wiki:q.is_moving dummy
BP/functions/wiki/detect_state/player/is_moving.mcfunction
yaml
## Movement Detection
### Mark as not moving
execute as @a at @s positioned ~~10000~ if entity @e[type=leash_knot,r=0.1252] run scoreboard players set @s wiki:q.is_moving 0
### Mark as moving
execute as @a at @s positioned ~~10000~ unless entity @e[type=leash_knot, r=0.1252] run scoreboard players add @s wiki:q.is_moving 1

## Update Point
### Delete previous point
execute as @e[type=leash_knot] at @s unless entity @s[y=-80, dy=9974] run kill @s
### Mark current point
execute at @a positioned ~~10000~ run summon leash_knot ~~~

## Your Commands Here (Examples)
execute as @a[scores=wiki:q.is_moving=0}] run say I'm not moving
execute as @a[scores=wiki:q.is_moving=1}] run say I started moving
execute as @a[scores=wiki:q.is_moving=1..}] run say I'm still moving
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

commandBlockChain7

It is a requirement to follow this same sequence and properly apply the scores selector argument as shown for your desired commands.

States:

  • wiki:q.is_moving=0 target is not moving.
  • wiki:q.is_moving=1 target started moving. (used for 'trigger' actions)
  • wiki:q.is_moving=1.. target is still moving. (used for repeating actions)

Purpose of Each Command:

  • Command 1: If there is a Leash Knot above them, it means they have not moved from their "point" from the previous game-tick. Marking them as not moving (0)
    • Leash Knot is a Vanilla entity with anti-gravity behaviour which serves as a static entity for this system.
  • Command 2: If there isn't a Leash Knot above them, it means they have displaced from their "point" from the previous game-tick. Marking them as moving (1) by adding a score.
    • The score will keep incrementing if they keep moving without pause. Allowing us to use single-execution commands each time they start moving.
  • Command 3: We need to delete all previous "points" (kill old Leash Knots) to minimise entity lag. We will also avoid affecting any Leash Knots below the ~10000 height not involved in this system.
    • we are using the volume filter instead of a simple name filter to do that, because Leash Knots cannot be named.
  • Command 4: We will summon a new Leash Knot ~10000 blocks above the player to mark the point they are currently at, which we will test-for in command 1 & 2, in the next game tick. (when this command block chain loops/repeats)
  • Command 5, 6, 7: These are example commands (for each state) which can be modified / expanded.

Differentiating Walking And Sprinting ​

If you desperately need to detect walking and sprinting separately solely using commands, you may use this technique below.

Known Issue:

Walk/Sprint Detection may not work as intended with effects & enchantments.

BP/functions/wiki/detect_state/player/is_moving.mcfunction
yaml
## Movement Detection
### Mark as not moving
execute as @a at @s positioned ~~10000~ if entity @e[type=leash_knot,r=0.1252] run scoreboard players set @s wiki:q.is_moving 0
### Mark as moving
execute as @a at @s positioned ~~10000~ unless entity @e[type=leash_knot,r=0.1252] run scoreboard players add @s wiki:q.is_moving 1

## Walk Detection
### Mark as not walking
scoreboard players set @a wiki:q.is_walking 0
### Mark as walking
execute as @a at @s positioned ~~10000~ if entity @e[type=leash_knot,rm=0.21585,r=0.2805] run scoreboard players set @s wiki:q.is_walking 1

## Sprint Detection
### Mark as not sprinting
scoreboard players set @a wiki:q.is_sprinting 0
### Mark as sprinting
execute as @a at @s positioned ~~10000~ if entity @e[type=leash_knot, rm=0.2806,r=0.9] run scoreboard players set @s wiki:q.is_sprinting 1

## Update Point
### Delete previous point
execute as @e[type=leash_knot] at @s unless entity @s[y=-80,dy=9974] run kill @s
### Mark current point
execute at @a positioned ~~10000~ run summon leash_knot ~~~

## Your Commands Here (Examples)
execute as @a[scores={wiki:q.is_walking=0}] run say I'm not walking
execute as @a[scores={wiki:q.is_walking=1}] run say I'm walking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

commandBlockChain10

All the commands function the same way as explained previously. The only difference being the values used in the distance arguments r & rm for the walk/sprint detection commands.

Calculation for the values are given below:

Movement TypeAverage Speed in m/s
(blocks per second)
Average Speed
(blocks per game tick)
Walking4.317 m/s4.317 / 20 = 0.21585
Sprinting5.612 m/s5.612 / 20 = 0.28060
Sprint-Jumping7.127 m/s7.127 / 20 = 0.35635

Note: We will not be able to properly use single-execution commands from the walk/sprint detection due to their varying speed. Hence, the commands for the two will be a bit simpler. Also note that jumping while walking has a speed that fluctuates between that of walk and sprint.

  • Walk Detection Commands:
    1. The player is marked as not walking (0) by default.
    2. The player is marked as walking (1) if their displacement is between 0.21585 and 0.2805 blocks.
      • 0.2805 is just below sprinting speed.
  • Sprint Detection Commands:
    1. The player is marked as not sprinting (0) by default.
    2. The player is marked as sprinting (1) if their displacement is between 0.2806 and 0.9 blocks.
      • Change the value from 0.9 to 0.35635 if you wish to separate sprint-jumping from sprinting despite its fluctuating speed.

is_sleeping ​

This technique allows you to detect when the player is/isn't sleeping.

Note: When sleeping, the player's hitbox is reduced to 0.2 blocks.

Commands:

  • Make sure you add the wiki:q.is_sleeping scoreboard objective:
    • /scoreboard objectives add wiki:wiki:q.is_sleeping dummy
BP/functions/wiki/detect_state/player/is_sleeping.mcfunction
yaml
## Sleep Detection
### Mark as not sleeping
execute as @a at @s if entity @s[y=~0.3, dy=0] scoreboard players set @s wiki:q.is_sleeping 0
### Mark as sleeping
execute as @a at @s unless entity @s[y=~0.3, dy=0] run scoreboard players add @s wiki:q.is_sleeping 1

## Your Commands Here (Examples)
execute as @a[scores={wiki:q.is_sleeping=0}] run say I'm not sleeping
execute as @a[scores={wiki:q.is_sleeping=1}] run say I started sleeping
execute as @a[scores={wiki:q.is_sleeping=1..}] run say I'm still sleeping
1
2
3
4
5
6
7
8
9
10

commandBlockChain5

It is a requirement to follow this same sequence and properly apply the scores selector argument as shown for your desired commands.

States:

  • wiki:q.is_sleeping=0 player is not sleeping.
  • wiki:q.is_sleeping=1 player started sleeping. (used for 'trigger' actions)
  • wiki:q.is_sleeping=1.. player is still sleeping. (used for repeating actions)

Purpose of Each Command:

  • Command 1: If the player's hitbox is higher than 0.2 blocks, we mark them as not sleeping (0)
  • Command 2: If the player's hitbox is not higher than 0.2 blocks, we mark them as sleeping (1) by adding a score.
    • The score will keep incrementing if they don't stop sleeping. Allowing us to use single-execution commands each time they start sleeping.
  • Command 3, 4, 5: These are example commands (for each state) which can be modified / expanded.

is_sneaking ​

This technique allows you to detect when the player is/isn't sneaking.

Thanks to the introduction of Short Sneaking parity in 1.20.10 which reduces the player hitbox to 1.5 blocks when sneaking, making a proper sneak-detection using just commands is now possible which previously required add-on assistance.

Commands:

  • Make sure you add the wiki:q.is_sneaking scoreboard objective:
    • /scoreboard objectives add wiki:wiki:q.is_sneaking dummy
BP/functions/wiki/detect_state/player/is_sneaking.mcfunction
yaml
## Sneak Detection
### Mark as not sneaking
execute as @a at @s if entity @s[y=~1.5, dy=0] run scoreboard players set @s wiki:q.is_sneaking 0
### Mark as sneaking
execute as @a at @s unless entity @s[y=~1.5, dy=0] if entity @s[y=~0.7, dy=0] run scoreboard players add @s wiki:q.is_sneaking 1

## Your Commands Here (Examples)
execute as @a[scores={wiki:q.is_sneaking=0}] run say I'm not sneaking
execute as @a[scores={wiki:q.is_sneaking=1}] run say I started sneaking
execute as @a[scores={wiki:q.is_sneaking=1..}] run say I'm still sneaking
1
2
3
4
5
6
7
8
9
10

commandBlockChain5

It is a requirement to follow this same sequence and properly apply the scores selector argument as shown for your desired commands.

States:

  • wiki:q.is_sneaking=0 player is not sneaking.
  • wiki:q.is_sneaking=1 player started sneaking. (used for 'trigger' actions)
  • wiki:q.is_sneaking=1.. player is still sneaking. (used for repeating actions)

Purpose of Each Command:

  • Command 1: If the player's hitbox is higher than 1.4 blocks, we mark them as not sneaking (0)
  • Command 2: If the player's hitbox is not higher than 1.4 blocks, we mark them as sneaking (1) by adding a score.
    • The score will keep incrementing if they don't stop sneaking. Allowing us to use single-execution commands each time they start sneaking.
    • To prevent false-triggers when sleeping or crawling, we will also require their hitbox to be higher than 0.6 blocks.
  • Command 3, 4, 5: These are example commands (for each state) which can be modified / expanded.

is_crawling ​

This technique allows you to detect when the player is/isn't crawling.

Note: When crawling, the player's hitbox is reduced to 0.6 blocks.

Known Issue:

Swimming in water or gliding with Elytra will be detected as crawling.

Commands:

  • Make sure you add the wiki:q.is_crawling scoreboard objective:
    • /scoreboard objectives add wiki:wiki:q.is_crawling dummy
BP/functions/wiki/detect_state/player/is_crawling.mcfunction
yaml
## Crawl Detection
### Mark as not crawling
execute as @a at @s if entity @s[y=~0.7, dy=0] run scoreboard players set @s wiki:q.is_crawling 0
### Mark as crawling
execute as @a at @s unless entity @s[y=~0.7, dy=0] if entity @s[y=~0.3, dy=0] run scoreboard players add @s wiki:q.is_crawling 1

## Your Commands Here (Examples)
execute as @a[scores={wiki:q.is_crawling=0}] run say I'm not crawling
execute as @a[scores={wiki:q.is_crawling=1}] run say I started crawling
execute as @a[scores={wiki:q.is_crawling=1..}] run say I'm still crawling
1
2
3
4
5
6
7
8
9
10

commandBlockChain5

It is a requirement to follow this same sequence and properly apply the scores selector argument as shown for your desired commands.

States:

  • wiki:q.is_crawling=0 player is not crawling.
  • wiki:q.is_crawling=1 player started crawling. (used for 'trigger' actions)
  • wiki:q.is_crawling=1.. player is still crawling. (used for repeating actions)

Purpose of Each Command:

  • Command 1: If the player's hitbox is higher than 0.6 blocks, we mark them as not crawling (0)
  • Command 2: If the player's hitbox is not higher than 0.6 blocks, we mark them as crawling (1) by adding a score.
    • The score will keep incrementing if they don't stop crawling. Allowing us to use single-execution commands each time they start crawling.
    • To prevent false-triggers when sleeping, we will require their hitbox to be higher than 0.2 blocks.
  • Command 3, 4, 5: These are example commands (for each state) which can be modified / expanded.

Differentiating Crawling, Gliding And Swimming ​

If you desperately need to detect all three states separately solely using commands, you may use this technique below.

Known Issues:

  1. Gliding while touching the ground/ceiling or crashing straight into a wall will be detected as crawling.
  2. Crawling from absolute corner of a block while wearing an Elytra, with no adjacent blocks above or below, will be detected as gliding.
    • issue2
  3. Swimming in a waterlogged block under another waterlogged block will be detected as crawling.
    • issue3
BP/functions/wiki/detect_state/player/is_crawling.mcfunction
yaml
## Set Player States
### Not gliding
execute as @a at @s if entity @s[y=~0.7, dy=0] run scoreboard players set @s wiki:q.is_gliding 0
### Not crawling
execute as @a at @s if entity @s[y=~0.7, dy=0] run scoreboard players set @s wiki:q.is_crawling 0
### Not swimming
execute as @a at @s if entity @s[y=~0.7, dy=0] run scoreboard players set @s wiki:q.is_swimming 0

## Detect Player States
### Gliding
execute as @a[hasitem={item=elytra,location=slot.armor.chest}] at @s unless entity @s[y=~0.7,dy=0] if entity @s[y=~0.3,dy=0] if block ~~1.01~ air if block ~~-0.01~ air rotated ~ 0 if block ^^1.01^-1 air if block ^^-0.01^-1 air if block ^^1.01^1 air if block ^^-0.01^1 air run scoreboard players add @s wiki:q.is_gliding 1
### Crawling
execute as @a[scores={wiki:q.is_gliding=0}] at @s unless entity @s[y=~0.7,dy=0] if entity @s[y=~0.3,dy=0] unless block ~~~ water unless block ~~1.01~ water run scoreboard players add @s wiki:q.is_crawling 1
### Swimming
execute as @a[scores={wiki:q.is_gliding=0,wiki:q.is_crawling=0}] at @s unless entity @s[y=~0.7, dy=0] if entity @s[y=~0.3,dy=0] run scoreboard players add @s wiki:q.is_swimming 1

## Your Commands Here (Examples)
execute as @a[scores={wiki:q.is_swimming=0}] run say I'm not swimming
execute as @a[scores={wiki:q.is_crawling=1}] run say I started crawling
execute as @a[scores={wiki:q.is_gliding=1..}] run say I'm still gliding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

commandBlockChain9

Purpose of Each Command:

  • Command 1, 2, 3: If the player's hitbox is higher than 0.6 blocks, we mark them as not gliding/crawling/swimming (0)
  • Command 4: If the player's hitbox is not higher than 0.6 blocks, has equiped an elytra, and has no blocks above/below their head/chest/feet, we mark them as gliding (1) by adding a score.
    • The score will keep incrementing if they don't stop gliding. Allowing us to use single-execution commands each time they start gliding. We will employ the same for crawling/gliding.
    • To prevent false-triggers when sleeping, we will also require their hitbox to be higher than 0.2 blocks. We will employ the same for crawling/gliding.
  • Command 5: If the player's hitbox is not higher than 0.6 blocks, is not gliding, and has no water above/below them, we mark them as crawling (1) by adding a score.
  • Command 6: If the player's hitbox is not higher than 0.6 blocks, is not gliding or crawling, we mark them as swimming (1) by adding a score.
  • Command 7, 8, 9: These are example commands (for each state) which can be modified / expanded.

Folder Structure ​

If you are working with functions, your folder structure may look something like this:

            • 📝is_moving.mcfunction
            • 📝is_sleeping.mcfunction
            • 📝is_crawling.mcfunction
      • 📝tick.json
    • 📝manifest.json
    • 🖼️pack_icon.png

Contributors

Edit Movement Detections on GitHub

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository