Add force for long pass ball

Hi
How to add correct forces for ball pass. For simple pass I do it that way

rb.AddForce((target.position - transform.position) * thrust, ForceMode.Impulse);

so basicaly I calculate direction and apply some thurst (kick power). It behavior a little strange because it looks that summary force depends on how far the target.position is o_0. And second question when I want to make long pass I do it that

rb.AddForce(transform.up * 5, ForceMode.Impulse); // this should add vertical force to move ball up
rb.AddForce((target.position - transform.position) * thrust, ForceMode.Impulse); 

but it don’t work correctly because ball sometimes go to diferent direction (because I think of this rb.AddForce(transform.up * 5, ForceMode.Impulse):wink:

Hallo.

First Qust:
AddForce is a vector. Doing this;

 target.position - transform.position

You calculate a vector with the correct direction, but the magnitude of the vector depends on the distance between the 2 points. To have a better control of the force, you should convert that vector into a known magnitude vector with the same direction. Best way to do this is to Normalize the vector (so the magnitude will be always 1)


Second Qst:

Meybe the best solution if you want a parabole trajectory, is to add the vertical movement as a simple translate function (or changing directly its transform.position.y) To have a correct control of the height.

I think a good solution can be, once you know the origin and final points, you can calculate the middle point of that 2 points. Then while the object is moving increase its Y component a little each frame, until reach the midpoint (midpoint in X and Z components, as Y will change). Once reached this midpoint, decrease Y component again.

Good luck!

Bye!