# How could we curve a ball in a football kick going from source to destination?

I have tweened the ball from one point to other.

``````if(this.kick == false) return;

if (this.val > 1) return;

this.val += dt;
var target = KickFootball.v1;
target.lerp(this.src, this.des, this.ease( this.val ));
this.entity.setPosition(target);``````

If you aren’t using physics you will have to use some equation to calculate that trajectory.

And these two things come to my mind that may be of help:

2 Likes

You can also find a maxima of the curve, say 2 meters to the side of a straight path which is from point A to point B.

You can find that normal by using a cross product of the path direction (from A to B) and an up vector (`pc.Vec3.UP` or `pc.Vec3.DOWN`, depending on whether you want go left or right from the path). Since we want 2 meters, we multiply the final vector by 2 and then lerp and add it to the target (just lerp it twice as fast, so that it would reach its maxima in the middle of the path, for example)

``````const offset = new pc.Vec3();

const pathDirection = endPoint.clone().sub(startPoint).normalize();
const side = new pc.Vec3().cross(pathDirection, pc.Vec3.UP).mulScalar(2);
const val = this.ease( this.val );

target.lerp(this.src, this.des, val);
// lerp from zero to 1, then back from 1 to zero
offset.lerp(pc.Vec3.ZERO, side, val < 0.5 ? val * 2 : 1 - (val * 2 - 1);