Minecraft Java Edition – How to Spawn an Entity with the Same Velocity as Another Entity?

minecraft-commandsminecraft-java-edition

I want to summon an arrow with the same velocity as an egg that has just been thrown. I know about the NBT tag Motion:[x,y,z], but I have no idea how to match that with the velocity of another entity.

I tried to just have the arrow be constantly be teleported to the egg, but it doesn't land where the egg lands.

Best Answer

You can transfer NBT data from one entity to another in newer versions of minecraft. To replace all eggs with arrows with the same Motion-tag, you could use these three commands, executed in a repeating command block and then two chain command blocks:

/execute at @e[type=egg] run summon minecraft:arrow ~ ~ ~
/execute as @e[type=minecraft:arrow] at @s run data modify entity @s Motion set from entity @e[type=egg,distance=0,limit=1] Motion
/kill @e[type=egg]

The first command summons an arrow at the position of every egg.

The second command sets the Motion-tag of every arrow to the same value as any egg that is in exactly the same position.

The third command kills all eggs.