第一个速度计算的球没有到达它应该去的目标

The first speed calculated ball does not go to the target it should go

In the function below, The distance between ball and target is known(R). Also, the angle between the resultant vector and the x-axis is known(LaunchAngle). Thanks to these parameters(R, LaunchAngle), I calculate the initial velocity of a ball. I checked all the values. According to physics, they are all correct. Although all calculations are correct, the ball does not hit the target.

void LaunchFromTargetPositionWithoutFrictionForce()
        {
            Vector3 projectileXZPos = new Vector3(transform.position.x, 0.0f, transform.position.z);
            Vector3 targetXZPos = new Vector3(TargetObjectTF.position.x, 0.0f, TargetObjectTF.position.z);
            transform.LookAt(targetXZPos);

            float R = Vector3.Distance(projectileXZPos, targetXZPos);
            float G = -Physics.gravity.y;

            float Vz = Mathf.Sqrt(G * R / Mathf.Sin((2.0f * LaunchAngle) * Mathf.Deg2Rad));
            float Vy = Vz * Mathf.Sin(LaunchAngle * Mathf.Deg2Rad);
            float Vx = Vz * Mathf.Cos(LaunchAngle * Mathf.Deg2Rad);
            text2.text = "vz: " + Vz.ToString() + " vy: " + Vy.ToString() + " vx: " + Vx.ToString();

            Vector3 localVelocity = new Vector3(0f, Vy, Vx);
            Vector3 globalVelocity = transform.TransformDirection(localVelocity);


            rigid.velocity = globalVelocity;
            bTargetReady = true;

            if (isSlowMotion) timeManager.slowMotion();
        }

球的第一个位置

并且在二维运动之后它在目标之前被击中

我用以下代码更改了前 3 行。问题解决了。

    Vector3 projectileXZPos = transform.position;
    Vector3 targetXZPos = TargetObjectTF.position;
    float dist = Vector3.Distance(projectileXZPos, targetXZPos);
    transform.LookAt(targetXZPos);