I am trying to modify the damage an arrow does without the use of the power enchantment. The damage of an arrow scales with speed it has so I am looking for a mechanism to determine its resultant speed (this is probably gonna be a math-based post, heads up).
The motion tag of an arrow contains x motion, y motion, and z motion which are components of the velocity vector (basically you do some trigonometry with all 3 components to determine the resultant velocity vector which indicates the net speed [magnitude] and direction the arrow travels at a particular point in time). I really do not care about what direction the arrow is travelling as much as I care about the overall speed the arrow travels.
Is there a simple way that does not require a million commands that can detect just the speed an arrow travels? The mechanism I am proposing for modifying the damage the arrow does requires a scale (see below for example), and a repeating command block will run data merge @e[type=arrow (arrow travelling at a particular speed)] {damage:(inserted damage value that correlates to an arrow travelling at the particular speed)}.
Example of the 'Scale':
Speed of Arrow: 1-5 ------------- Damage Arrow Will Do: 2.0
Speed of Arrow: 5-10 ------------- Damage Arrow Will Do: 3.0
Speed of Arrow: 10-15 ------------- Damage Arrow Will Do: 4.0
*I understand that these are not the actual speeds an arrow will attain when shot from a bow, but the chosen values are for simplicity.
Well, I've not been thought trigonometry at school, so calculate the magnitude somehow yourself and then feed it in a dummy scoreboard (called "value" here) :
In the datapack(I assume) you'll have to have these commands run at load to initialize the scoreboards:
scoreboard objectives add value dummy
scoreboard players set #divide value 5
scoreboard players set #add value 1
Have this command run every tick:
exexute as @e[type=arrow] positioned as @s if entity @e[type=!item, distance=..1] run function <function name>
In the function:
<complicated commands to calculate magnitude and set it to arrow's 'value'>
scoreboard players operation @s value /= #divide value
scoreboard players operation @s value += #add value
execute store entity @s damage int 1 run scoreboard players get @s value
Note:
1)Check syntax yourself, on phone right now. Although, I'm pretty sure that these will work
2)Commands work in function in 1 tick, so commands work before arrow hits target
Edit: 1) Elaborated the instructions
2) did what you actually wanted, currently given magnitude is calculated, arrow will deal (x/5)+1 half hearts of damage
Thanks for the help! I actually realized that the damage tag of arrows doesn't determine the actual damage of the arrow, its more of a 'baseline' damage. The actual damage is determined already from the speed of the arrow, so I have no need to try the system I made before.
I am trying to modify the damage an arrow does without the use of the power enchantment. The damage of an arrow scales with speed it has so I am looking for a mechanism to determine its resultant speed (this is probably gonna be a math-based post, heads up).
The motion tag of an arrow contains x motion, y motion, and z motion which are components of the velocity vector (basically you do some trigonometry with all 3 components to determine the resultant velocity vector which indicates the net speed [magnitude] and direction the arrow travels at a particular point in time). I really do not care about what direction the arrow is travelling as much as I care about the overall speed the arrow travels.
Is there a simple way that does not require a million commands that can detect just the speed an arrow travels? The mechanism I am proposing for modifying the damage the arrow does requires a scale (see below for example), and a repeating command block will run data merge @e[type=arrow (arrow travelling at a particular speed)] {damage:(inserted damage value that correlates to an arrow travelling at the particular speed)}.
Example of the 'Scale':
Speed of Arrow: 1-5 ------------- Damage Arrow Will Do: 2.0
Speed of Arrow: 5-10 ------------- Damage Arrow Will Do: 3.0
Speed of Arrow: 10-15 ------------- Damage Arrow Will Do: 4.0
*I understand that these are not the actual speeds an arrow will attain when shot from a bow, but the chosen values are for simplicity.
All help is appreciated, thank you!
The Big Dog
Well, I've not been thought trigonometry at school, so calculate the magnitude somehow yourself and then feed it in a dummy scoreboard (called "value" here) :
In the datapack(I assume) you'll have to have these commands run at load to initialize the scoreboards:
Have this command run every tick:
In the function:
Note:
1)Check syntax yourself, on phone right now. Although, I'm pretty sure that these will work
2)Commands work in function in 1 tick, so commands work before arrow hits target
Edit: 1) Elaborated the instructions
2) did what you actually wanted, currently given magnitude is calculated, arrow will deal (x/5)+1 half hearts of damage
Perseverance always pays. Sooner or later.
If you can create a mathematical expression using trigonometry, I might be able to translate that into minecraft
Perseverance always pays. Sooner or later.
Thanks for the help! I actually realized that the damage tag of arrows doesn't determine the actual damage of the arrow, its more of a 'baseline' damage. The actual damage is determined already from the speed of the arrow, so I have no need to try the system I made before.
The Big Dog