how to target a 3d tank gun

i have a tank ai but im having alot of trouble setting it up to aim at the player. please take into consideration that its 3d and its not a 2d aim straight at target, i want it realistic. so far i’ve been going pointlessly about and ive finally come here to see if anyone has figured out how to do it. so far my script has an attempt at figuring out the angle i need to achieve a var distance.
private var player:Transform;

private var distance:float;

private var time:float;

private var Rotx:float;

private var Roty:float;

private var Rotz:float;

private var x:float;

private var velx:float;

private var vely:float;

private var velz:float;

function Start(){player = gameObject.FindWithTag(“Player”).transform;}

function Update () {

var rotation = Quaternion(Rotx,Roty,Rotz,0):Quaternion;

velx = Mathf.Sin(transform.rotation.x * Mathf.Deg2Rad)*250;

Rotx = 1/2 * Mathf.Asin((32.2distance)/velxvelx);

vely = Mathf.Sin(transform.rotation.y * Mathf.Deg2Rad)*250;

Roty = 1/2 * Mathf.Asin((32.2distance)/velyvely);

velz = Mathf.Sin(transform.rotation.z * Mathf.Deg2Rad)*250;

Rotz = 1/2 * Mathf.Asin((32.2distance)/velzvelz);

distance = Vector3.Distance(player.position, transform.position);

transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime);

}
this is my current script, spot any errors, make suggestions, throw in a completely different code, this one has random errors and i have no idea what a w is in a quaternion

If I understand correctly, you're just asking for a way to find the distance from the canon to your player? I think that can be achieved with something like:

`
// Drop your player onto the "player" variable in the Inspector
var player : GameObject;
// Then, likely in the Update() or LateUpdate() function, you can use something
// like this...
Vector3.Distance(player.transform.position, transform.position;
// And to see the distance in the log, you can...
Debug.Log("The distance to the player is: " + Vector3.Distance(player.transform.position, transform.position));
`

I hope that helps somewhat.

no. as you see i already have the distance, i already have the velocity, and i already have gravity, i want an angle, not something i already have.