Calculating force

I have two points: A launch point, and a target. I have a script that calculates the force i need to apply to my object, so it lands on my target.

[Formula] (http://i.ajdesigner.com/projectilemotion/range_equation_initial_velocity.png) where v0 is initial velocity, R is the range, g is the acceleration of gravity, and θ is the angle.

This works fine, but only if the y-axis of my launch point and target are the same. How can i calculate the force i need, but also being able to hit my target, even if it is above or below me.

Code:`using UnityEngine;
using System.Collections;

public class LobbTest : MonoBehaviour {

public int roundTo;
public Transform target;

private Rigidbody rb;
private float range;
private float gravity;
private float angle;
private float velocity;
private float angleRad;

public void Lobb () 
{
	rb = GetComponent<Rigidbody> ();

    range = target.position.x - transform.position.x;
	Debug.Log ("range = " + range);
	gravity = -Physics.gravity.y;
	Debug.Log ("gravity = " + gravity);
	angle = transform.eulerAngles.z;
	Debug.Log ("angle = " + angle);

	velocity = (Mathf.Sqrt ((range * gravity) / CalculateSine(angle, 2)));

	Debug.Log ("velocty = " + velocity);

	rb.velocity = transform.right * velocity;

}

float CalculateSine(float angle, float multiplier)
{
	float radAngle = angle * Mathf.PI / 180f;
	float radSine = Mathf.Sin (multiplier * radAngle);

	radSine = Round (radSine, roundTo);

	return radSine;
}

float Round(float f, int roundTo)
{
	return Mathf.Round (f * Mathf.Pow(10, roundTo)) / Mathf.Pow(10, roundTo); 
}`

}

yes. slightly different derivation than above, but:

// speed = +/- sqrt( GX^2 / (2C * (SX - CY)) )
// where
// X, Y = location of target
// C, S = cosine & sine of theta
// G = gravity

float speed = float.NaN;

float C2_times_SX_minus_CY = 2f * C * ((S * X) - (C * Y));
float G_times_X_SQUARED    = G * X * X;

if (Mathf.Approximately(C2_times_SX_minus_CY, 0f)) {
  // divide by zero
}
else if (C2_times_SX_minus_CY < 0f) {
  // imaginary answer
}
else {
  // hokay
  speed = Mathf.Sqrt(G_times_X_SQUARED / C2_times_SX_minus_CY);
}

you’ll need to modify this to deal with the fact that your launch point is not at the origin (or reconfigure scene so that is), and also this formula gives you the launch speed, but you’re asking for the launch force. i’m not sure how to compute the force from the speed, but hopefully that’s relatively simple.
also, if you allow the launch angle to be pointing in the opposite direction from the target, this formula will produce a wrong result, because it’s assuming the “+” portion of “+/-” sqrt().

i put up a live demo here

fun stuff !