simple trajectory for rigidbody

Hello. I am trying to implement a sort of simple projectile trajectory system for my AI. Currently, it’s using a quick n dirty Transform.LookAt for the targets position. I would like the upwards angle ( the x axis, it’s a 2D game) to increase by X amount based on the distance from the target. I want to create a type of arch looking movement. Also, should I use addforce if I want it to be accurate? or something more like a Lerp?

There are a number of formulas you can use for simple projectile motion. The trick is you have to figure out what variables you want to vary. If you strictly want to vary the angle then you can use one formula:

 Given:
 Distance from target = R
 angle Theta;
 Velocity.magnitude = v
 gravity = 9.8f

 v^2 * sin(2Theta) / 9.8 = R

 Solve for Theta:
 Theta = asin(dg/v^2)/2

That’s about as simple as you can make it. In code terms, it looks more like this:

var velocity : float;

function Launch () {
       var theta : float = 0;
       var distance = (target.position - lauchPosition).x;

       theta = .5 * Mathf.Asin(distance * 9.8 / velocity / velocity);

       rigidbody.AddForce( velocity * new Vector3(Mathf.Cos(theta), Mathf.Sin(theta), 0) , ForceMode.VelocityChange);
}

// Animates the position in an arc between sunrise and sunset.

var sunrise : Transform;
var sunset : Transform;

function Update () {
// The center of the arc
var center = (sunrise.position + sunset.position) * 0.5;
// move the center a bit downwards to make the arc vertical
center -= Vector3(0,1,0);

// Interpolate over the arc relative to center
var riseRelCenter = sunrise.position - center;
var setRelCenter = sunset.position - center;
transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, Time.time);
transform.position += center;
}