Unity will actually do all of the simulation for you. Given you are providing the vertical component \$T\$ of the force, all you need is the horizontal component \$\vec{H}\$, So all you need to do is re-arrange the equations so that, given your inputs, you get that component:
$$\vec{F} = \vec{H} + T \vec{up}$$
In Unity: Vector3 F = H + T * Vector3.up;
. With that you can apply the force in Unity with rigidbody.AddForce(F, ForceMode.Impulse);
.
To get the horizontal force \$\vec{H}\$, you will need the mass of your projectile \$m\$ and the horizontal velocity \$\vec{h}\$ that you want to achieve:
$$\vec{H} = \vec{h}m$$
The mass you can get from rigidbody.mass
but the horizontal velocity you will need to calculate, and for that, you will need to know the travel time \$t\$ and the vector \$\vec{AB}\$ from \$a\$ to \$b\$:
$$\vec{h} = \frac{\vec{AB}}{t}$$
You can find \$\vec{AB}\$ in Unity with Vector3 AB = b - a
. But to find the travel time \$t\$ (how long the projectile is in the air) you need to know the upward velocity \$u\$ and your gravity \$g\$:
$$t = \frac{2u}{g}$$
Nearly there. To find the upward velocity \$u\$ you need again the mass \$m\$ of your projectile and the upward force \$T\$ that you are supplying:
$$u = \frac{T}{m}$$
And so finally your code would be:
float u = T / rigidbody.mass;
float t = 2 * u / Physics.gravity.magnitude;
Vector3 AB = b - a;
Vector3 h = AB / t;
Vector3 H = h * rigidbody.mass;
Vector3 F = H + T * Vector3.up;
rigidbody.AddForce(F, ForceMode.Impulse);
b
,discriminant
,discRoot
,T_min
, andT_max
and just useT = T_lowEnergy * multiplier
. At the end this gives you the launch velocity of the projectile you can assign to its body directly. Or if you need it as an impulse, that's(launchVelocity - currentVelocity) * mass
. – DMGregory Mar 13 '24 at 10:35T
you calculate here is total time airborne (in seconds), so you can clamp this below some max if you want to make sure the lob isn't too slow when the object is far away. In other answers I also show how to parametrize this by the altitude of the apex of the arc, if you'd like to control the arc height that way. – DMGregory Mar 13 '24 at 10:38