Cant calculate bullet trajectory

I want to program an archer for the first time. I made a movement code for the arrow and the trajectory calculation for the bow. The problem is, that the bow is not aiming high enough to hit the target or is not aiming low enough to hit it.
Code for the bow:

arrowFlightDistance = Vector3.Distance(transform.position, targetPosition.position);
timearrival  = arrowFlightDistance / (arrowSpeed );
upposition = Mathf.Tan(Mathf.Asin( 0.5f * arrowGravity *  (timearrival * timearrival) / arrowSpeed )) * arrowFlightDistance;
transform.LookAt(new Vector3(targetPosition.position.x, targetPosition.transform.position.y + upposition, targetPosition.position.z));

Code for the Arrow:

        downSpeed += downAcceleration* Time.deltaTime * Time.deltaTime;
        transform.position += transform.forward * speed * Time.deltaTime;
        transform.position -= Vector3.up * downSpeed;

I tried removing the Time.deltaTime but then my arrows get shot way too fast and if i add them to my bow code it can not calculate anything. If I let the arrow rotate in movement direction it will come too short. I am out of options right now and need help.

I made an old post about a similar topic here (https://answers.unity.com/questions/1087568/3d-trajectory-prediction.html#answer-1087707) (albeit using the built-in physics for the simulation rather than updating the position manually). It might prove to be a handy example to base your efforts on.

That said, while the way that you’re applying motion to your arrow has simplified aerodynamic merit, it would add a significant degree of complexity to the problem.

By applying forward motion based on transform.forward while simultaneously pulling toward a global/gravity down, the forward motion could essentially be pulling in any direction. It could even continue pulling straight up, even while gravity is winning/pulling down against it!

Edit: For reference, your “downAcceleration” variable would be the magnitude of the “gravityBase” example in my old answer:

// Something like...
Vector3 gravity = Vector3.down * downAcceleration;

Calculating all elements regarding physics makes you crazy.
You may try to do with RigidBody rather than those Mathf things

    GetComponent<Rigidbody>().AddForce(new Vector3(), ForceMode.Impulse);