This question already has an answer here:
I've seen a lot of tutorials for detecting the player at certain X,Y,Z coordinates, but I want to detect only the player's Y coordinate. In this situation I want to detect the player at Y level 18. I tried things like
execute if entity @a[y=18.5,distance=1.5] but that doesn't work.
execute if entity @a[x=~,y=18.5,z=~,distance=1.5] doesn't work either. Do I need different commands?