I am working on a mod in Minecraft Forge/MCP using Java.
Aiming a bow is controlled by your head pitch and yaw rotation. Right now I have a math function that automatically looks at the target. But I simply cannot figure out how to increase the pitch (up-down rotation of your head) to look higher based on how far the target is away. This is necessary because arrows naturally fall downwards, so you have to aim higher, to account for your arrow falling over down over time. How high you aim is based on how far your target is. If you aim to high, the arrow will fly over their head, whereas if you aim to low, the arrow will hit the ground before reaching the target.
I tried the basic stuff like the following:
pitch += distanceToTarget / 4 // Distance is measured in blocks
What I am looking for is a method, that when called, will return the amount I have to add to the pitch to account for the arrow falling down. As mentioned previously, it has to be very precise or the arrow likely won't hit the target.
I don't need exact Java code for this; while that would be preferred, I only need to know the logic, which doesn't necessarily have to be in Java.
Thank you very much for the help!
P.S.: This is only for educational purposes, I'm not trying to use this to hack any servers (so please no hate, thanks! :D).
EDIT: According to this question, the Minecraft arrow travels at
About 60.5 to 60.8 blocks per second.
EDIT 2: I looked at this question shown to me by DMGregory and I looked at this Minecraft fandom page. I learned the following peice of infomation:
When fired, arrows fly in a ballistic trajectory affected by gravity and drag in air, water, and lava. The arrow's velocity is multiplied by 0.99 every tick, and it also experiences 1 m/s2 of gravity.
Arrows travel approximately 3 blocks when fired parallel to a flat plane with no charge, 15 blocks average with medium charge, and 24 blocks average with maximum charge. When fired from a fully charged bow, arrows can travel 120 blocks if fired from an optimal angle. The maximum height an arrow fired by a bow can reach is around 66 blocks.
Thanks for the help, but I still cannot figure out exactly how I can accomplish this task.