Here's a video by MNSweet demonstrating rotational direction detection:
Rather than checking the NBT data (i.e. using {}
), rotation can be tested for using the target selector arguments ry
, rym
, rx
, and rxm
, denoting the maximum and minimum view angle in the horizontal (east, south, etc.) and vertical (up, down) direction, respectively.
For example, to test for someone looking South (=0±22), use
testfor @a[ry=22,rym=-22]
To test for someone looking 45° upwards (±10) and to the northeast (=135±22)
testfor @a[ry=-113,rym=-157,rx=55,rxm=35]
See Commands wiki page for more information.
This can be done with the health
scoreboard. Create an objective with:
/scoreboard objectives create h health
This creates an objective h
, which tracks player's health (by number of half-hearts).
Change your command to:
execute @a[score_h_min=1] ~ ~ ~ say hi
This only triggers if the player has at least a half-heart (they're alive).
Best Answer
I figured it out. It turns out that that it should be:
execute unless entity @a[x_rotation=0.9,y_rotation=-179.0]
since the x and y are flipped compared to the co-ords. It should also be something like:execute unless entity @a[x_rotation=-0.5..0.9,y_rotation=175.0..181.0]
so it targets players between certain values rather than specific ones. If you imagine something rotating on the y-axis it would be theoretically be spinning left to right or right to left and on the x-axis it would be spinning up and down.