1

As most minecraft command makers know, entering ~ instead of a coordinate number results in the relative position of the executing entity. Apparently, the /tp command has a special property with relative coordinates.

I am trying to make a command that teleports all other entities to the same position as the player, but on a absolute Z value. This will make a third person, 2D-looking effect. Here's my command:

execute @p ~ ~ ~ /tp @e[type=!Player,r=20] ~ ~ -645

This does not work. In the /tp command, it appears that the ~s are no longer relative to the executing entity, but the entity being teleported.

A similar command works like I expect it to. It places a block at the player's position, but again at a fixed z position:

execute @p ~ ~ ~ /setblock ~ ~ -650 minecraft:stone

I am wondering how to make the ~s in the /tp command to execute relative to the executing entity, not the entity being teleported.

Both the commands are inside a repeating, non-conditional, redstone-requiring command blocks. They are both powered by levers.

I am on Minecraft 1.12 Mac edition, singleplayer world.

Any help is appreciated! Thanks in advance!

3
execute @p ~ ~ ~ /teleport @e[type=!player,r=20] ~ ~ -645

teleport is a command added in 1.10 that behaves exactly like tp, except that coordinates are relative to the executor.

  • This works, but /teleport does not take absolute coordinates. I need a solution that can take both relative AND absolute. Thanks for the answer, though. – yummypasta Jun 22 '17 at 4:16
  • @yummypasta It certainly does, I just tested. – AjaxGb Jun 22 '17 at 4:21
  • Interesting... my command /execute @p ~ ~ ~ /teleport @e[type=!Player] ~ ~ -645 does not move the entity's z axis at all... it stays in it's initial Z position. The command should teleport it to the -645 position on Z. This is strange, as I just did some more testing to find that it does indeed take absolute values. Is this a bug? – yummypasta Jun 22 '17 at 4:25
  • execute @p ~ ~ ~ teleport @e[type=chicken] ~ ~ -45 works absolutely fine for me. the chicken always was at -45 in the z axis, following my movement in the x and y axis. – Plagiatus Jun 22 '17 at 9:11
  • Must have been a glitch in my commands/typo. It now works. I accepted your answer. Thanks! – yummypasta Jun 22 '17 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.