Leading a target using LookAt().

I have a simple turret mesh that tracks the player using the LookAt() function. The player uses a Character Controller component. I'd like to be able to create an Inspector adjustable 'leadTarget' variable that adds to movement direction of the Player.

I simply need to know how to return that movement direction.

If your character movement is in Update and your turret LookAt were in LateUpdate, your turret would look at where your character has moved to this frame. If both are in update, this is not guaranteed to be the case.

If you are looking for a lead this frame based on their current movement and your projectile speed and distance, etc. You could store the player's movement as a public (maybe even static) variable. If the variable is public, you need only access the instance with GetComponent(ScriptName) (or scriptName.variableName if the variable is static as well).

Character.js

static var movement : Vector3 = Vector3.zero;                        //static
//var movement : Vector3 = Vector3.zero;                             //not static
var speed : float = 3.0f;
private var controller : CharacterController;

function Start() {
    controller = GetComponent(CharacterController);
}

function Update() {
    movement = Vector3(Input.GetAxis("Horizontal"), 0.0f,
                       Input.GetAxis("Vertical"));
    movement = transform.TransformDirection(movement);;
    movement *= speed;
    controller.Move(movement * Time.deltaTime);
    //controller.SimpleMove(movement);                               //or this
}

Turret.js

var target : Transform;
var projectile : Transform;

//lead is movement * distance/projectile speed
function LateUpdate() {
    if(target) {
        //var script : Character = target.GetComponent(Character);   //not static
        var aimPosition : Vector3 = target.position;
        var lead : Vector3 = Character.movement;                     //static
        //var lead : Vector3 = script.movement;                      //not static
        lead *= (transform.position - target.position).magnitude / 
                ProjectileScript.speed;
        transform.LookAt(aimPosition + lead);
    }
}

If you don't want to share the variable or are concerned about gravity and collisions generated by the `CharacterController`'s `Move` or `SimpleMove`, then you needn't store the extra variable, but can access the publicly accessible `CharacterController.veclocity`. Note that the docs on this parameter clearly state:

Note: The velocity returned is simply the difference in distance for the current timestep before and after a call to CharacterController.Move or CharacterController.SimpleMove. The velocity is relative because it won't track movements to the transform that happen outside of the CharacterController (e.g. character parented under another moving Transform, such as a moving vehicle).

Turret.js

var target : Transform;
var projectile : Transform;

//lead is movement * distance/projectile speed
function LateUpdate() {
    if(target) {
        var controller: CharacterController = 
            target.GetComponent(CharacterController);
        var aimPosition : Vector3 = target.position;
        var lead : Vector3 = controller.velocity;
        lead *= (transform.position - target.position).magnitude / 
                ProjectileScript.speed;
        transform.LookAt(aimPosition + lead);
    }
}