Arqade Asked on April 24, 2021
I want to summon an arrow that is fired in the same direction as the player that it is summoned closest to, is this possible with just commands and as minimal command blocks as possible? (not one command block for like ever 30°)
Currently I have tried summoning it without gravity and right after it spawns teleporting it using /execute as @e[type=arrow,name="guardarrow",scores={lifetime=1..1}] at @s rotated as @p run tp @s ~ ~ ~ ~ ~
(lifetime scoreboard is just +1 per tick) which for about 0.5s rotates the arrow and then it rotates back, making this method useless. Using the Motion:[x.x,x.x,x.x]
nbt doesn’t work since it has to be able to go in all directions. So is there any way to make this work properly?
Also: When teleporting the arrows to move them they apparently don’t hit things, they go straight through mobs
You said in the comments that you have multiple "guards" that each shoot at targets, potentially at the same time. That complicates the matter a bit, compared to this answer.
You need the scoreboards x
, y
and z
, all of type dummy
.
As a first step whenever you want something to fire I suggested creating a dummy entity that you can rotate towards the target, but I guess rotating the shooting entities themselves is probably better in your case:
execute as @e[shooter>] at @s run tp @s ~ ~ ~ facing entity @e[<selector for target>,limit=1]
Then you do basically the same as in my other answer, except that some things have to be done relative to the shooter, because just tagging the arrows doesn't work if there are multiple at the same time.
execute as @e[<shooter>] at @s run summon arrow ^ ^ ^1 {NoGravity:1}
execute as @e[type=arrow] store result score @s x run data get entity @s Pos[0] 10
execute as @e[type=arrow] store result score @s y run data get entity @s Pos[1] 10
execute as @e[type=arrow] store result score @s z run data get entity @s Pos[2] 10
execute as @e[type=armor_stand] store result score @s x run data get entity @s Pos[0] 10
execute as @e[type=armor_stand] store result score @s y run data get entity @s Pos[1] 10
execute as @e[type=armor_stand] store result score @s z run data get entity @s Pos[2] 10
execute as @e[type=armor_stand] at @s positioned ^ ^ ^1 run scoreboard players operation @e[type=arrow,distance=0] x -= @s x
execute as @e[type=armor_stand] at @s positioned ^ ^ ^1 run scoreboard players operation @e[type=arrow,distance=0] y -= @s y
execute as @e[type=armor_stand] at @s positioned ^ ^ ^1 run scoreboard players operation @e[type=arrow,distance=0] z -= @s z
execute as @e[type=arrow] store result entity @s Motion[0] double 0.1 run scoreboard players get @s x
execute as @e[type=arrow] store result entity @s Motion[1] double 0.1 run scoreboard players get @s y
execute as @e[type=arrow] store result entity @s Motion[2] double 0.1 run scoreboard players get @s z
You'll probably also want to tag the arrows in some way, so that you don't set their Motion
to 0 in the last step if they were fired from a bow or if you've already applied the motion to them (except if you want that).
Keep in mind that arrows lose a bit of speed over time, so it would at some point stop in midair. And the target can of course move. You can also adjust the scale factors (10
and 0.1
) if you want the arrows to be faster.
Answered by Fabian Röling on April 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP