How can I shoot an arrow and have it always hit an enemy?
I had a little thought about your question. It is not possible to change the direction of an arrow towards somebody, because you need vector calculations for that, which aren't possible in minecraft commands.
I think I have found an interesting alternative for you. The idea is that when an arrow hits the ground, close to the player, then it summons an invisible baby zombie with an arrow as rider. This baby zombie tries to move to the closest player. Once the baby zombie has arrived to its target, it gets killed and an arrow is summoned just above the player's head, making it seem as if the player got hit.
It works as following:
# give all the arrows in the ground a tag. [repeat] [unconditional] [always active]
/scoreboard players tag @e[type=arrow] add hit {inGround:1b}
# summon an invisible baby zombie at the location of the arrow with an arrow as passenger [chain] [unconditional] [always active]
/execute @e[tag=hit] ~ ~ ~ summon zombie ~ ~ ~ {IsBaby:1,Tags:["arrowZombie"],ActiveEffects:[{Id:14,Amplifier:0,Duration:20000000,ShowParticles:0b}],Passengers:[{id:arrow}]}
# delete the original arrow [chain] [unconditional] [always active]
/kill @e[tag=hit]
Now start a new chain of command blocks:
# check if the baby zombie is close to a player and summon an arrow above this player's head [repeat] [unconditional] [always active]
/execute @e[tag=arrowZombie] ~ ~ ~ execute @p[r=1] ~ ~ ~ summon Arrow ~ ~2.1 ~
# kill all baby zombies that are close to a player [chain] [unconditional] [always active]
/execute @a ~ ~ ~ kill @e[tag=arrowZombie,r=1]
following is an image of how an invisible baby zombie with an arrow as rider looks like:
This method has a few drawbacks though:
- The baby zombie has to see the player in order to track it, so the zombie doesn't always navigate towards the target.
- Every arrow that hits the ground summons a baby zombie. This is easily fixable, but I leave that up to you to figure out.
- If the arrow lands above a cliff, the baby zombie will fall down and die.
- Arrow effects and bow enchantments don't work with this method, because you summon a new arrow.
It's up to you to decide if this method suits your needs. Even if this doesn't work quite the way you want it, I'm sure you'll have a lot of fun testing it.
You can also leave the baby zombie part out and just summon an arrow above the head of the player closest to the original arrow, but once again: I'll leave that up to you to figure out.