3

I have been trying to test if a player is at specific coordinates using this command in a command block:

execute as @a[x=-166,y=4,z=-120,distance=3] run say cool  

But nothing happens when I trigger it. If I take the distance=3 part out it works even if I'm not at the coordinates stated.

What I'm doing wrong?

0

2 Answers 2

3

So I did some research, and it turns out that the way [x=X,y=Y,z=Z] works without a distance selector is different than what it used to be:

Selects targets based on distance to that exact position. Combine with selecting by radius to select only targets at that specific position.

Basically, distance is being automatically filled with the distance from the executing position (in this case, the command block) to the coordinates supplied.

When you use the selector form of distance=3, you're saying you want players that are exactly 3 metres away from the coordinates specified, and given that coordinates are floating point values, that's basically impossible without teleporting them to a specific position. Instead, you want to use a range, such as distance=2..3 (2 to 3 metres away), distance=..3 (less than/equal to 3 metres away), or distance=3.. (greater than/equal to 3 metres away).

0

You can use the positioned component to specify the executing position and then use distance to specify the distance from that position, in your case [distance=0..1].

Unfortunately typing distance=1 or [distance=0] doesn't work, because you have to be EXACTLY at one of these two distances, like millimetres-exact, so you have to use a range of 0 block distance and 1 block distance. And if the execution succeeds when you're still a few steps away from that block, you can change the value of '1' to a number between '0' and '1' like '0.8', which means [distance=0..0.8] (note that the two dots are max/min selectors: if you type any number before the two dots, that's the minimum value, and the one after the two dots is the maximum value).

1
  • You should add an example of a full row of command. Btw, as it is, it looks like your answer haven't brought much more than the one already existing.
    – Zoma
    Sep 24, 2019 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .