Download

Calculate force required to move a ball from A to B

Hi,

I am playing around with a soccer game and can’t figure out what force I need to apply to the ball (Static Mesh -> Add Force) to pass it from location A to a target location B. The source and the target locations will always be on the XY plane and I can calculate the vector from one to the other (e.g. (100, 100, 0) if the target is 100 units to the right and in front of the source) but I need to add a Z amount and some sort of multiplication so that the ball leaves the ground and lands at the target and I don’t know how much. I’ve randomly tried things like Z=50% of the length of the vector with a multiplier of 100 as in the image but it’s not happening for me. The ball moves in the correct direction towards the target but with completely the wrong power - underhit for short passes and overhit for long passes.

7efc2d6e280fad5b42443b0bdf80e238583ffc90.png

Can anyone help?

Thanks.

You need to solve a differential equation for this, because at each simulation step, the ball will lose some linear damping of its velocity (and, if rolling, some friction.)
There’s also a question of how quickly you want the ball to get there, and whether you want it to get there and stop, or just bounce along afterwards.
If what you want is just to bounce at the target, and then keep going, and you are flying in the air with minimal dampening, then you can calculate the trajectory as a parabola.
Pick an angle upwards that you want to shoot the ball (there are actually infinitely many of these) and calculate the upwards force such that the acceleration over time reaches exactly the negative of the initial velocity at the arrival point, then make the total velocity such that the ball gets to the destination in exactly that time.
Then, turn velocity into impulse – which is hard in UE physics because it doesn’t use a fixed time step. You can cheat by clicking the “set velocity, not force” checkbox though.

So, in math:
The time of flight is t
The movement in XY is exactly d, so XY velocity is d/t
Gravity is g
The initial upwards velocity is vZ (you get to pick this)
This means that the time of flight comes from (2vZ = tg)
So, the initial velocity you want is V = (d/t)(XY)+vZ(Z)
So, the initial impulse you want is V * mass / impulse-length

Thanks a lot for the pointers, I think I’m nearly there now. Here is what I’ve come up with in case anyone else wants to use it. Note that I’m using centimetres so my gravity variable is set as 981, not 9.81. The height of the arc I’m currently arbitrarily setting at 1/4 the distance but I’m going to tweak this so that longer passes have a higher arc than shorter ones.

3853ad751a2fd67837798006fa6be83d1df6409a.jpeg

Now for a new thread about how to draw the trajectory…

I know this is two-and-a-half years later, but this blueprinting allowed me to create a launchpad mock-up in about thirty minutes. Thanks so much everyone; especially Johnny Peanuts II for the screenshot!