I am making a map that requires the detection of a players leftward/rightward motion (Not turning and walking, but specifically pressing the A and D buttons) to rotate an armor stand in correlation with that left or right motion. I am attempting to store the result of the players left/right motion in a scoreboard (objective is "motionX") to see if it works, but the command shown below does not seem to increase/decrease the score when I tested it. If i'm making an error, please help. thanks.
execute as @a store result score @a Motion run data get entity @s Motion[0] 1
I am making a map that requires the detection of a players leftward/rightward motion (Not turning and walking, but specifically pressing the A and D buttons) to rotate an armor stand in correlation with that left or right motion. I am attempting to store the result of the players left/right motion in a scoreboard (objective is "motionX") to see if it works, but the command shown below does not seem to increase/decrease the score when I tested it. If i'm making an error, please help. thanks.
execute as @a store result score @a Motion run data get entity @s Motion[0] 1
Are players restricted to move directly leftward/rightward? (i.e. did you lock their rotation so that they can only face a certain degree?)
If so, you "probably" need to change a little bit in your command. Here's my try:
execute as @a store result score @s motionX run data get entity @s Motion[0]
The rotation of the player won't be locked at a certain degree.
If that's the case, it can't be done with just 1 command...
Lemme ask you a few things before I begin:
1. Does it have to be DIRECTLY left/right? Can they move diagonally to be detected?
2. When do you need to check that? When something approaches? Every single tick? When you need to activate certain skill?
3. If, by any chance, you're doing something like mirrors, can you just use /tp?
I may ask more questions if I'm not clear. I'd like to know what you're truly making to simplify the case, but it's fine if you don't want to spoil the content.
1. The direction does not need to be directly left or right, just in that general direction
2. I need to check it every single tick
3. I am not doing mirrors, more like a 2D platformer type of thing where the armor stand flips around in the direction it is walking.
1. The direction does not need to be directly left or right, just in that general direction
2. I need to check it every single tick
3. I am not doing mirrors, more like a 2D platformer type of thing where the armor stand flips around in the direction it is walking.
If it's just a 2D platform game, you can/must lock the rotation right?
I'm really asking because locking the rotation makes everything way easier.
I am locking the players rotation to a small area in their field of vision so that they cannot look too far up and cannot look too far down, but the player does need to be able to look around.
I am locking the players rotation to a small area in their field of vision so that they cannot look too far up and cannot look too far down, but the player does need to be able to look around.
TL;DR If the player can still rotate 360 degree, it's not 2D and thus won't work. Otherwise, copy.
Ok. Got it done.
Before I begin, here's a few limitations:
1. The horizontal rotation is limited to -80 to 80. The thing will malfunction if you go beyond this range. So if your 2D plane is not facing North (i.e. the player is not facing South), try to move it if possible. If not, it'll make things kinda complicated.
2. It's currently limited to 1 player. If it's multiplayer, I need to limit the ranges.
Ok. Here we go:
Impulse
/scoreboard objectives add LR_move dummy
/scoreboard players set 36000 LR_move 36000
/execute at @p run summon minecraft:armor_stand ~ ~ ~ {Invisible:1,NoGravity:1,Marker:1,Invulnerable:1,Tags:["LR_detect"]}
Repeating
/execute as @e[tag=LR_detect] at @s if entity @a[distance=0.01..1] run tag @s add LR_moved
/execute as @e[tag=LR_moved] at @s run teleport @s ~ ~ ~ facing entity @p[distance=..1]
/execute as @e[tag=LR_moved] store result score @s LR_move run data get entity @s Rotation[0] 100
/execute at @e[tag=LR_moved] as @p[distance=..1] store result score @s LR_move run data get entity @s Rotation[0] 100
/execute as @a[scores={LR_move=18001..}] run scoreboard players remove @s LR_move 36000
/execute as @a[scores={LR_move=..-18001}] run scoreboard players add @s LR_move 36000
/execute as @e[tag=LR_moved] at @s run scoreboard players operation @s LR_move -= @p[distance=..1] LR_move
/execute as @e[tag=LR_detect] at @s run teleport @s @p
/tag @e[tag=LR_moved] remove LR_moved
/execute if entity @e[tag=LR_detect,scores={LR_move=-13500..-4500}] run title @a title "You moved left."
/execute if entity @e[tag=LR_detect,scores={LR_move=4500..13500}] run title @a title "You moved right."
That should be it. Make sure the player can at least move half a block before being teleported back.
there is another issue with this. I am trying to animate my armor stand whenever I walk to the left or right, but that messes with the left or right turning.
there is another issue with this. I am trying to animate my armor stand whenever I walk to the left or right, but that messes with the left or right turning.
How will it mess with the turning?
I assume that the armor stand only rotated halfway?
I am trying to rotate it either left or right (setting its rotation data to 90 or -90 degrees, not teleporting it, in case that has something to do with the issue) and change the pose of its left and right legs to make it look animated, but it only rotates a portion of that direction when the leg pose data is changed. I uploaded a picture showing the armor stand not fully rotated left or right. The score on the sidebar named walkingstages2D is increased by 1 in a repeating command block until it hits 55, and that determines what point in the animation the armor stand is at.
I am trying to rotate it either left or right (setting its rotation data to 90 or -90 degrees, not teleporting it, in case that has something to do with the issue) and change the pose of its left and right legs to make it look animated, but it only rotates a portion of that direction when the leg pose data is changed. I uploaded a picture showing the armor stand not fully rotated left or right. The score on the sidebar named walkingstages2D is increased by 1 in a repeating command block until it hits 55, and that determines what point in the animation the armor stand is at.
I think I had this issue. Just to confirm:
1. When it rotates and shows an incomplete turn, have you try to get its rotation (by /execute store or by teleporting to it)? Its actual rotation should be different than what it shows.
2. Apart from my command, is there any more commands you used to teleport it?
3. Is the rotation back to normal when you close and open the world?
1. I just tried teleporting to it and its actual rotation is not the same as its showing.
2. I rotated the armor stand based on its "LR_move" score, so between two scores for left, and between two other scores for right. I took out the commands that displayed the title "you moved left" and "you moved right." I also used the scoreboard and commands mentioned in my previous reply for the animation part.
3. The rotation does switch back to normal when I reload the world.
1. I just tried teleporting to it and its actual rotation is not the same as its showing.
2. I rotated the armor stand based on its "LR_move" score, so between two scores for left, and between two other scores for right. I took out the commands that displayed the title "you moved left" and "you moved right." I also used the scoreboard and commands mentioned in my previous reply for the animation part.
3. The rotation does switch back to normal when I reload the world.
Yep, that's exactly the issue I'm thinking about.
When you do /teleportfor ANY mob, DO NOT make it repeating. The /teleport command tend to interrupt the turning if the entity is gon-na rotate 90+ degree. (It's a bug, deal with it: https://bugs.mojang.com/browse/MC-132158) Hence, what you can do is to make every /teleportcommand work only once on the armor stand, not repeating.
Yours is just rotate left and right, pretty sure it's not hard to do, unlike mine... : p
I am making a map that requires the detection of a players leftward/rightward motion (Not turning and walking, but specifically pressing the A and D buttons) to rotate an armor stand in correlation with that left or right motion. I am attempting to store the result of the players left/right motion in a scoreboard (objective is "motionX") to see if it works, but the command shown below does not seem to increase/decrease the score when I tested it. If i'm making an error, please help. thanks.
execute as @a store result score @a Motion run data get entity @s Motion[0] 1
Are players restricted to move directly leftward/rightward? (i.e. did you lock their rotation so that they can only face a certain degree?)
If so, you "probably" need to change a little bit in your command. Here's my try:
execute as @a store result score @s motionX run data get entity @s Motion[0]
The rotation of the player won't be locked at a certain degree.
If that's the case, it can't be done with just 1 command...
Lemme ask you a few things before I begin:
1. Does it have to be DIRECTLY left/right? Can they move diagonally to be detected?
2. When do you need to check that? When something approaches? Every single tick? When you need to activate certain skill?
3. If, by any chance, you're doing something like mirrors, can you just use /tp?
I may ask more questions if I'm not clear. I'd like to know what you're truly making to simplify the case, but it's fine if you don't want to spoil the content.
1. The direction does not need to be directly left or right, just in that general direction
2. I need to check it every single tick
3. I am not doing mirrors, more like a 2D platformer type of thing where the armor stand flips around in the direction it is walking.
If it's just a 2D platform game, you can/must lock the rotation right?
I'm really asking because locking the rotation makes everything way easier.
I am locking the players rotation to a small area in their field of vision so that they cannot look too far up and cannot look too far down, but the player does need to be able to look around.
TL;DR If the player can still rotate 360 degree, it's not 2D and thus won't work. Otherwise, copy.
Ok. Got it done.
Before I begin, here's a few limitations:
1. The horizontal rotation is limited to -80 to 80. The thing will malfunction if you go beyond this range. So if your 2D plane is not facing North (i.e. the player is not facing South), try to move it if possible. If not, it'll make things kinda complicated.
2. It's currently limited to 1 player. If it's multiplayer, I need to limit the ranges.
Ok. Here we go:
Impulse
/scoreboard objectives add LR_move dummy
/scoreboard players set 36000 LR_move 36000
/execute at @p run summon minecraft:armor_stand ~ ~ ~ {Invisible:1,NoGravity:1,Marker:1,Invulnerable:1,Tags:["LR_detect"]}
Repeating
/execute as @e[tag=LR_detect] at @s if entity @a[distance=0.01..1] run tag @s add LR_moved
/execute as @e[tag=LR_moved] at @s run teleport @s ~ ~ ~ facing entity @p[distance=..1]
/execute as @e[tag=LR_moved] store result score @s LR_move run data get entity @s Rotation[0] 100
/execute at @e[tag=LR_moved] as @p[distance=..1] store result score @s LR_move run data get entity @s Rotation[0] 100
/execute as @a[scores={LR_move=18001..}] run scoreboard players remove @s LR_move 36000
/execute as @a[scores={LR_move=..-18001}] run scoreboard players add @s LR_move 36000
/execute as @e[tag=LR_moved] at @s run scoreboard players operation @s LR_move -= @p[distance=..1] LR_move
/execute as @e[tag=LR_detect] at @s run teleport @s @p
/tag @e[tag=LR_moved] remove LR_moved
/execute if entity @e[tag=LR_detect,scores={LR_move=-13500..-4500}] run title @a title "You moved left."
/execute if entity @e[tag=LR_detect,scores={LR_move=4500..13500}] run title @a title "You moved right."
That should be it. Make sure the player can at least move half a block before being teleported back.
Tell me if you have any questions.
this'll do the job. thank you so much bro
there is another issue with this. I am trying to animate my armor stand whenever I walk to the left or right, but that messes with the left or right turning.
How will it mess with the turning?
I assume that the armor stand only rotated halfway?
I am trying to rotate it either left or right (setting its rotation data to 90 or -90 degrees, not teleporting it, in case that has something to do with the issue) and change the pose of its left and right legs to make it look animated, but it only rotates a portion of that direction when the leg pose data is changed. I uploaded a picture showing the armor stand not fully rotated left or right. The score on the sidebar named walkingstages2D is increased by 1 in a repeating command block until it hits 55, and that determines what point in the animation the armor stand is at.
I think I had this issue. Just to confirm:
1. When it rotates and shows an incomplete turn, have you try to get its rotation (by /execute store or by teleporting to it)? Its actual rotation should be different than what it shows.
2. Apart from my command, is there any more commands you used to teleport it?
3. Is the rotation back to normal when you close and open the world?
1. I just tried teleporting to it and its actual rotation is not the same as its showing.
2. I rotated the armor stand based on its "LR_move" score, so between two scores for left, and between two other scores for right. I took out the commands that displayed the title "you moved left" and "you moved right." I also used the scoreboard and commands mentioned in my previous reply for the animation part.
3. The rotation does switch back to normal when I reload the world.
Yep, that's exactly the issue I'm thinking about.
When you do /teleport for ANY mob, DO NOT make it repeating. The /teleport command tend to interrupt the turning if the entity is gon-na rotate 90+ degree. (It's a bug, deal with it: https://bugs.mojang.com/browse/MC-132158) Hence, what you can do is to make every /teleport command work only once on the armor stand, not repeating.
Yours is just rotate left and right, pretty sure it's not hard to do, unlike mine... : p