1

I have an arrow who's motion I want to scale up so that it moves faster but still moves in the same direction. However, all I can figure out is how to set it to a single, unchanging value with /execute as @e[type=arrow] run data modify entity @s Motion set value [x,y,z] where x,y,z are constants. What I want to do is set these three values as a scaled value of what the values are currently. Does anyone know how to do this or at least push me in the right direction?

3
  • Each of the three separately, scoreboard temporarily, /execute store has scale factor argument. Scale the scoreboard much higher for more precision, but beware overflow. Jul 11, 2023 at 23:06
  • @FabianRöling Tried this, where I created a scoreboard objective for each velocity direction, then added the arrow in question as a player to each of the three objectives. Then via execute store I set the score to about 1000 times the velocity. Then I used execute store to set the velocity equal to the score. However, it didn't work and remained at the same velocity, however the scoreboard did show the scaled velocity value. This was the final command block in the chain execute as @e[type=arrow] store result entity @s Motion[0] double 1.001 run scoreboard players get @s xVel Jul 12, 2023 at 2:26
  • When I originally read this comment, I thought: "There's no way, surely the asker made a typo somewhere or something". I read the command many times and couldn't see any problem. Turns out, Minecraft is the problem. Took me quite a while to figure that out, too. Jul 12, 2023 at 6:59

1 Answer 1

1

The basic principle is to store the value in a scoreboard temporarily, using the scale factor of execute store and then putting it back into NBT. So something like this:

execute store result score foo y run data get entity @e[type=arrow,limit=1] Motion[1] 10
execute store result entity @e[type=arrow,limit=1] Motion[1] double 1 run scoreboard players get foo y

But there is a problem: Motion does not allow values >10.0. If you write e.g. 1000.0 into it, it will just get reset to 0. You could cap the value with something like this:

execute if score foo y matches 11.. run scoreboard players set foo y 10

But if you want large scale factors, you'll probably end up with lots of arrows that go perfectly in a 45° angle. Alternatively, you could disable all the normal logic of an arrow by giving it Motion=[0.0,0.0,0.0],NoAI=1,NoGravity=1 and teleporting it yourself by the intended distance each tick. To do that, you have to do calculations in scoreboards and then write the result to Pos.

6
  • Okay, and NoAI=1 will remove the standard velocity decay so that will move in the direction it was shot at the same velocity until it hits something? Jul 12, 2023 at 12:56
  • I think so. NoAI is a bit of a mess, especially between different versions. Try it. If not, use a Marker and teleport that around instead and then the arrow to it. But either way, this method looks quite buggy, the arrow will not smoothly animate correctly between positions. Motion is the only tag where this works correctly. Jul 12, 2023 at 16:04
  • Since arrows are an entity, they should have a rotation, right? So do you think that I could simply tell the arrow to teleport a small value in the direction it is facing Jul 12, 2023 at 16:38
  • Nope, arrows lie about their rotation. But that would be needlessly complicated anyway, you can just add Motion to Pos. Maybe you need to scale it first, but I don't think so. Modifying Pos is an alternative method of teleporting non-player entities and the only way to do it in a variable way (not typing the explicit amount). Jul 12, 2023 at 17:41
  • So how would I go about adding motion to Pos? Jul 12, 2023 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .