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.