How to spawn an entity with the same velocity as another entity?

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.


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.


The short answer is: you can't.


The longer answer is: You still can't, but here is why:
You can't transfer NBT data from one entity to another. Normally you might be able to work around that by detecting the NBT data in the first entity with a few hardcoded values, and then giving that same tag to the other entity.
This however won't work for the Motion tag since that incorporates three double values, and a typical Motion tag looks something like this: Motion[0.17361829472d,1.38572958294d,0.72483746234d] (good luck finding that one with hardcoded values)