Answers for "Mathematicians wanted = trajectory target hitting question"
http://answers.unity.com/questions/242624/mathematicians-wanted-trajectory-target-hitting-qu.html
The latest answers for the question "Mathematicians wanted = trajectory target hitting question"Answer by aldonaletto
http://answers.unity.com/answers/242681/view.html
If both objects are at the same height, things are easier. If they have different heights, however, the equation becomes too complicated, so complicated that I was not able to get the inverse function. But I used a simple trick to correct the trajectory when the height difference is relatively small compared to the horizontal distance (how much is "small" depends on the elevation angle). The idea is to aim closer or farther than the target distance in such a way that the trajectory passes through its actual position:
![alt text][1]
This trick works fine for relatively small differences, as I said, but since it relies on a straight line approximation of the trajectory near to the zero height point, the error grows with the height difference.<br>
You can see my answer with the complete ballistic calculation function in this question:
http://answers.unity3d.com/questions/148399/shooting-a-cannonball.html
**EDITED:** The equation you have is interesting because it takes the precise height difference into account, while mine just approximates it. Unfortunately, it returns the angle, not the velocity, and this complicate things a lot!<br>
My function does the opposite - returns a velocity vector for a given angle - but isn't so precise when the heights are different. Maybe you could combine both and try a numeric solution: find an initial angle based on the fence height and distance from the target, use my function to find the necessary velocity, refine the angle with your equation (the second one - the first always returns the higher angle) and check if the fence is being hit: if yes, increase the initial angle (multiply it by 1.10, for instance) and repeat the process.<br>
Just as a convenience, I posted the function BallisticVel below:
<pre>
function BallisticVel(target: Transform, angle: float): Vector3 {
var dir = target.position - transform.position; // get target direction
var h = dir.y; // get height difference
dir.y = 0; // retain only the horizontal direction
var dist = dir.magnitude ; // get horizontal distance
var a = angle * Mathf.Deg2Rad; // convert angle to radians
dir.y = dist * Mathf.Tan(a); // set dir to the elevation angle
dist += h / Mathf.Tan(a); // correct for small height differences
// calculate the velocity magnitude
var vel = Mathf.Sqrt(dist * Physics.gravity.magnitude / Mathf.Sin(2 * a));
// return the complete velocity vector
return vel * dir.normalized;
}
</pre>
[1]: http://www.draldo.com.br/data/ballistictrajectory.pngFri, 20 Apr 2012 15:54:23 GMTaldonalettoAnswer by fafase
http://answers.unity.com/answers/242671/view.html
I think I found something that could help you out.
http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra7
Go down the middle of the page to "Will it clear the fence?"
I thought that would be easier for you to read and understand than writing some (vel^2*sin^2(alpha))/2g = heightFri, 20 Apr 2012 15:37:56 GMTfafase