Minecraft – Moving damage effect

minecraft-commandsminecraft-java-edition

I've been trying to set up a command block in a mine cart, that does damage when a player is above it and 15 blocks along the Z axis, but it has to use tildes, right now I'm using:

/effect @a[x=~0,y=~4,z=~15] minecraft:instant_damage

Edit:
/effect @a[dx=0,dy=7,dz=26] minecraft:instant_damage

Works perfectly! I put the cart to the edge of the room (The rooms are about 30 blocks wide), and put activator rails below the cart to trigger the command.

Best Answer

Tildes cannot be used in target selector arguments. You must instead use an execute command. This command should execute it as the command block minecart.

/execute @e[c=1,r=0] ~ ~4 ~15 /effect @a[r=1] minecraft:instant_damage