- #1
dklompmaker
- 1
- 0
I have been toiling over this for the last three weeks. I am programming a tank to fire at a target. The target can be all over the landscape up, down left right. Currently I have the turret turn to face the target turning the problem into a 2d equation. So I need help finding the right equation for initial velocity to hit the target.
Basically I am doing the following.
tv = target.transform.position - transform.position; // This is a vector direction to my target
var g = -9.8; // Gravity
var r = Mathf.Abs(tv.z); // The range or x to my target
var a = Mathf.Sin(90); /
var v = Mathf.Sqrt((r * g ) / a); // Finally get my velocity and return it
return v;
I know these equations are wrong but I am having a hard time trying to figure out how to account for height differences, and get the correct initial velocity to fire the bullet to hit the target.
Thank you for your help!
Basically I am doing the following.
tv = target.transform.position - transform.position; // This is a vector direction to my target
var g = -9.8; // Gravity
var r = Mathf.Abs(tv.z); // The range or x to my target
var a = Mathf.Sin(90); /
var v = Mathf.Sqrt((r * g ) / a); // Finally get my velocity and return it
return v;
I know these equations are wrong but I am having a hard time trying to figure out how to account for height differences, and get the correct initial velocity to fire the bullet to hit the target.
Thank you for your help!