I need to make sure an entity has the same Y value as a player. Is there any way to do that?
I'm summoning the entity at ^ ^ ^3
relative to the player, and then I need it to teleport to the Y level of the player too, while conserving its X and Z. Is there any way to do that?
Best Answer
Since you only want to move non-player entities, you can simply copy your Y coordinate to theirs in NBT:
But that rounds down to the bottom of the block you're in, so for example the entity would fall through slabs if you are standing on slabs. You can increase the accuracy by scaling up when reading from NBT and scaling down when writing into NBT. Currently (1.15.2) all block heights are in steps of 1/32 of a block (archive). And if you're not standing on a block, then rounding down 1/32 shouldn't matter anyway. Using 64 as a scale factor gives you even better accuracy:
You will also not get any overflow issues with this scale factor, because if you were above y=33554432 for some reason, you would get kicked anyway.