I'm trying to detect if a player is standing still or moving. This command below is attempting to add 1 to a scoreboard "timer" when I'm standing still.
/execute as @a[nbt={Motion:[0.0,0.0,0.0]}] run scoreboard players add @s timer 1
As you probably could've guessed, this doesn't work. Even when I'm moving, it will still add 1.
For some odd reason, however, it stops when I'm sprinting and jumping (weird exception).
Player's motion, unlike other entities, is inaccurate most of the time unless they are jumping.
Therefore, it is highly recommended to use other method to detect if the player is moving.
You can store player's Pos[0], Pos[1], and Pos[2] into scoreboard in current tick, and compare it with what you store from the previous tick to see if the position had changed. (so 6 dummy scoreboard are need, 3 for storing current tick, 3 for storing previous tick).
Or you can use other criteria(some of them are probably duplicate, so choose only what movement you want to detect):
I'm trying to detect if a player is standing still or moving. This command below is attempting to add 1 to a scoreboard "timer" when I'm standing still.
/execute as @a[nbt={Motion:[0.0,0.0,0.0]}] run scoreboard players add @s timer 1
As you probably could've guessed, this doesn't work. Even when I'm moving, it will still add 1.
For some odd reason, however, it stops when I'm sprinting and jumping (weird exception).
Can you guys help me out?
One reason the command behaves that way (apart from player motion being messed up as was mentioned) is because when you test for data within a list (values surrounded by square brackets), each element within the list you specify is checked within every element on the target.
For example, if you checked for "List:[1]" and the target had a list of "List:[3,2,1]", it would match because your specified value of "1" is compared with the target's values of "3", "2", and "1", and it matched the last value. Therefore your test of "Motion:[0.0,0.0,0.0]" is the exact same as testing "Motion:[0.0]".
But for whatever reason, the player's X and Z motion will be 0 even when moving normally, so the check for Motion:[0.0] will always find at least 1 element. Sprint-jumping causes the values to actually update, and no motion values are 0 at that point, so the check fails.
As for the objectives, you'd create them like so (prepended with "minecraft.custom:minecraft."):
I have a similar problem but I am on Bedrock Edition, I've seen some solutions but personally I think they are cheap and usually buggy, anyone have a solution?
The reason motion is “messed up” for players is because the Motion tag only keeps track of involuntary Motion. That means any movement that is a result of player input (ie WADS) is not counted since it isn’t involuntary. However if the player is moved by something else like flowing water, explosions, knockback or they have momentum while in the air, it is counted as ‘voluntary’ and is stored in the Motion tag.
Non players are always tracked correctly because all of their movement is ‘involuntary’ as they are controlled by the server.
I'm trying to detect if a player is standing still or moving. This command below is attempting to add 1 to a scoreboard "timer" when I'm standing still.
/execute as @a[nbt={Motion:[0.0,0.0,0.0]}] run scoreboard players add @s timer 1
As you probably could've guessed, this doesn't work. Even when I'm moving, it will still add 1.
For some odd reason, however, it stops when I'm sprinting and jumping (weird exception).
Can you guys help me out?
Player's motion, unlike other entities, is inaccurate most of the time unless they are jumping.
Therefore, it is highly recommended to use other method to detect if the player is moving.
You can store player's Pos[0], Pos[1], and Pos[2] into scoreboard in current tick, and compare it with what you store from the previous tick to see if the position had changed. (so 6 dummy scoreboard are need, 3 for storing current tick, 3 for storing previous tick).
Or you can use other criteria(some of them are probably duplicate, so choose only what movement you want to detect):
climb_one_cm
crouch_one_cm
fall_one_cm
fly_one_cm
horse_one_cm
minecart_one_cm
jump
pig_one_cm
sprint_one_cm
swim_one_cm
walk_on_water_one_cm
walk_one_cm
walk_under_water_one_cm
What are these "other criteria"? Are they built in criteria for scoreboards? I can't seem to use them.
One reason the command behaves that way (apart from player motion being messed up as was mentioned) is because when you test for data within a list (values surrounded by square brackets), each element within the list you specify is checked within every element on the target.
For example, if you checked for "List:[1]" and the target had a list of "List:[3,2,1]", it would match because your specified value of "1" is compared with the target's values of "3", "2", and "1", and it matched the last value. Therefore your test of "Motion:[0.0,0.0,0.0]" is the exact same as testing "Motion:[0.0]".
But for whatever reason, the player's X and Z motion will be 0 even when moving normally, so the check for Motion:[0.0] will always find at least 1 element. Sprint-jumping causes the values to actually update, and no motion values are 0 at that point, so the check fails.
As for the objectives, you'd create them like so (prepended with "minecraft.custom:minecraft."):
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
Thanks! This should work.
I have a similar problem but I am on Bedrock Edition, I've seen some solutions but personally I think they are cheap and usually buggy, anyone have a solution?
The reason motion is “messed up” for players is because the Motion tag only keeps track of involuntary Motion. That means any movement that is a result of player input (ie WADS) is not counted since it isn’t involuntary. However if the player is moved by something else like flowing water, explosions, knockback or they have momentum while in the air, it is counted as ‘voluntary’ and is stored in the Motion tag.
Non players are always tracked correctly because all of their movement is ‘involuntary’ as they are controlled by the server.