TransWikia.com

Teleport entities relatively to the center of a block

Arqade Asked by bw2801 on February 6, 2021

I just wanted to teleport an entity relatively, but the entity is not exactly in the middle of a block.

For example the coordinates are 0.3, 63.0, 0.76 and I teleport the entity relatively using ~1 ~0 ~1. The resulting coordinated will be 1.3, 63.0, 1.76 but I want the entity to be in the center of the block. So it has to be 1.5, 63.0, 1.5 instead.

Is it possible to achieve this? Thank you!

3 Answers

First, teleport or summon the entity relatively as you're doing at the moment.

There are a few ways to center an entity on a block. Some of the more clunky methods involve teleporting the entity elsewhere, shoving it against the corner and then teleporting it ~0.3 ~ ~0.3, or similar things.

The method I think works best is by using paintings or item frames. When summoned, they're always at the same location in the block:

http://i.imgur.com/vlq6Zmp.png

They're horizontally centered, and -0.469 off on the Z axis. This means that to center yourself, you can teleport to an item frame, and then teleport ~0.469.

So your order of commands should be something like this:

Your relative teleport/summon
/execute @e[name=Name] ~ ~ ~ /summon ItemFrame
/execute @e[name=Name] ~ ~ ~ /tp @e[type=ItemFrame,c=1,r=1]
/tp @e[name=Name] ~ ~ ~0.469
/execute @e[name=Name] ~ ~ ~ /kill @e[type=ItemFrame,c=1,r=1]

Answered by SirBenet on February 6, 2021

You can use Leash Knots like this:

/execute @e[name=Name] ~ ~ ~ /summon leash_knot ~ ~ ~ {CustomName:Centre}

/tp @e[name=Name] @e[name=Centre,c=1]

/kill @e[name=Centre]

(This is for 1.11, for 1.10 or lower use LeashKnot instead of leash_knot)

For 1.13+:

/execute as @e[name=Name] at ~ ~ ~ /summon leash_knot ~ ~ ~ {Tags:["Centre"]}

/tp @e[name=Name] @e[tag=Centre,limit=1]

/kill @e[tag=Centre]

Answered by Ubsje on February 6, 2021

When summoning relatively to command blocks, like ~ ~5 ~, it will summon it in the middle of the block.

Or, you can use a spawn egg, because when you use a spawn egg to spawn a zombie, the zombie will be in the middle of the block. So you can use execute and summon something at the zombie then kill the zombie.

Answered by Asteroid on February 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP