Given the arrow origin position, direction, force, gravity and drag, how can I calculate the arrow Y at a given X,Z ?
https://en.m.wikipedia.org/wiki/Projectile_motion Can someone help me understand all this. Do PocketMine projectiles even have such a motion as described in this wikipedia page?
The Projectile movement calculation is implemented here: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L1167 Velocity vector change per movement tick when the arrow is in air: Code: v.y = v.y * (1 - drag) - gravity v.x = v.x * (1 - drag) v.z = v.z * (1 - drag) Given initial velocity vector [v.x(0), v.y(0), v.z(0)], starting at the origin (0, 0, 0), the velocity at time t (after t ticks) can be expressed parametrically: Code: v.x(t) = v.x(0) * (1 - drag)^t v.z(t) = v.z(0) * (1 - drag)^t where ^ is the exponent operator The vertical velocity is a bit more tricky: Code: y[t] = y[t - 1] * (1 - drag) - gravity Applying z-transform (or just some tweaks with the sum of geometric sequence), you can derive a general formula for y[t]. You can derive the t using the v.x(t) or v.z(t) formula (if it is horizontal/vertical, you need to use the other axis; otherwise, either one is OK). Then you can calculate y[t] using the t. I am in a hurry so I don't have time to calculate it. Try it yourself
Code: f = (1 - drag) v.x(t) = v.x(0) * f^t v.z(t) = v.z(0) * f^t v.y(t) = v.y(0) * [f - gravity]^t Ok, this was easy. Now, to calculate the t at a given X/Z, I think this should be ok: Code: v.x(t) = v.x(0) * f^t v.x(t)/v.x(0) = f^t t = logf(v.x(t)/v.x(0)) Is this the best way to do it?