Hi, so I was working on a command block system where if you walked on to a certain block it will teleport you 1 block in the direction you're going but I can't figure out how to detect what direction a player is moving, I can't use ^ ^ ^1 since that would just teleport them in the direction they're looking not moving I think I could use something with /execute store with Motion[] but I'm not sure, any help is appreciated.
Here is what I use. This system detects the direction the player is moving in by comparing the current and the previous position of the player. It can't detect diagonal movement though.
Create the following objectives:
/scoreboard objectives add x dummy
/scoreboard objectives add z dummy
/scoreboard objectives add prev_x dummy
/scoreboard objectives add prev_z dummy
build a chain of command blocks and paste these commands into the chain (in order):
execute as @a store result score @s x run data get entity @s Pos[0]
execute as @a store result score @s z run data get entity @s Pos[2]
execute as @a if score @s x > @s prev_x run tag @s add x+
execute as @a if score @s x < @s prev_x run tag @s add x-
execute as @a if score @s z > @s prev_z run tag @s add z+
execute as @a if score @s z < @s prev_z run tag @s add z-
execute as @a run scoreboard players operation @s prev_x = @s x
execute as @a run scoreboard players operation @s prev_z = @s z
execute as @a[tag=x+] run <command>
execute as @a[tag=x-] run <command>
execute as @a[tag=z+] run <command>
execute as @a[tag=z-] run <command>
tag @e remove x+
tag @e remove x-
tag @e remove z+
tag @e remove z-
The system stores the player's x and z positions into the corresponding objectives and then compares it to the previous position (stored in the prev_x and prev_z objectives). If the value of x is greater than the value of prev_x, that means the player has moved towards the positive x-axis. The same goes for the z-axis.
Here is what I use. This system detects the direction the player is moving in by comparing the current and the previous position of the player. It can't detect diagonal movement though.
Create the following objectives:
/scoreboard objectives add x dummy
/scoreboard objectives add z dummy
/scoreboard objectives add prev_x dummy
/scoreboard objectives add prev_z dummy
build a chain of command blocks and paste these commands into the chain (in order):
execute as @a store result score @s x run data get entity @s Pos[0]
execute as @a store result score @s z run data get entity @s Pos[2]
execute as @a if score @s x > @s prev_x run tag @s add x+
execute as @a if score @s x < @s prev_x run tag @s add x-
execute as @a if score @s z > @s prev_z run tag @s add z+
execute as @a if score @s z < @s prev_z run tag @s add z-
execute as @a run scoreboard players operation @s prev_x = @s x
execute as @a run scoreboard players operation @s prev_z = @s z
execute as @a[tag=x+] run <command>
execute as @a[tag=x-] run <command>
execute as @a[tag=z+] run <command>
execute as @a[tag=z-] run <command>
tag @e remove x+
tag @e remove x-
tag @e remove z+
tag @e remove z-
The system stores the player's x and z positions into the corresponding objectives and then compares it to the previous position (stored in the prev_x and prev_z objectives). If the value of x is greater than the value of prev_x, that means the player has moved towards the positive x-axis. The same goes for the z-axis.
This doesn't seem like the specific system I need but I think I can modify it a bit to fit my specific needs, so thank you very much for your answer.
Hi, so I was working on a command block system where if you walked on to a certain block it will teleport you 1 block in the direction you're going but I can't figure out how to detect what direction a player is moving, I can't use ^ ^ ^1 since that would just teleport them in the direction they're looking not moving I think I could use something with /execute store with Motion[] but I'm not sure, any help is appreciated.
Here is what I use. This system detects the direction the player is moving in by comparing the current and the previous position of the player. It can't detect diagonal movement though.
Create the following objectives:
build a chain of command blocks and paste these commands into the chain (in order):
The system stores the player's x and z positions into the corresponding objectives and then compares it to the previous position (stored in the prev_x and prev_z objectives). If the value of x is greater than the value of prev_x, that means the player has moved towards the positive x-axis. The same goes for the z-axis.
Command block engineer // Developer // #TeamTrees
This doesn't seem like the specific system I need but I think I can modify it a bit to fit my specific needs, so thank you very much for your answer.