My turrets do not follow the enemy!

UPDATED AGAIN: Here is my script. My turrets fire correctly! but still do not follow the enemy…

var myProjectile : GameObject;
var reloadTime : float = 1f;
var turnSpeed : float = 5f;
var fireSpeed : float = .25f;
var muzzleEffect : GameObject;
var errorAmount : float = .001;
var myTarget : Transform;
var muzzlePositions : Transform[];
var turretBall : Transform;
 
private var nextFireTime : float = .5f;
private var nextMoveTime : float = .5f;
private var desiredRotation : Quaternion;
private var aimError : float =.5f;
 
function start() {
 
}
 
function Update() {
 
if(myTarget) {
 
if(Time.time >= nextMoveTime) {
 
CalculateAimPosition(myTarget.position);
turretBall.rotation = Quaternion.Lerp(turretBall.rotation, desiredRotation, Time.deltaTime*turnSpeed);
 
}
 
if(Time.time>= nextFireTime) {
 
FireProjectile();
 
}
}
}
 
 
function OnTriggerEnter(other : Collider) {
Debug.Log( "Trigger Enter");
if(other.GameObject.tag == "Enemy"){
 
nextFireTime = Time.time+(reloadTime*.5);
myTarget = other.GameObject.transform;
 
}
 
}
 
function OnTriggerExit(other : Collider) {
 
if(other.GameObject.transform == myTarget){
 
myTarget = null;
 
}
}
 
function CalculateAimPosition(targetpos : Vector3) {
 
var aimPoint = Vector3(targetpos.x+aimError, targetpos.y+aimError, targetpos.z+aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
 
function CalculateAimError() {
 
aimError = Random.Range(-errorAmount, errorAmount);
 
}
 
function FireProjectile() {
 
audio.Play();
nextFireTime = Time.time+reloadTime;
nextMoveTime = Time.time+nextFireTime;
CalculateAimError();
        
for(theMuzzlePos in muzzlePositions) {
 
 
Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
 
}
}

You should use Time.time instead of Time.deltaTime. You use Time.deltaTime right only once in the Quaternion.Lerp()

function Update() { 
   if(myTarget) { 
      if(Time.time >= nextMoveTime) { 
         ...
      }
 
      ...
   }
}

function FireProjectile() {
   audio.Play();
   nextFireTime = Time.time + reloadTime;
   nextMoveTime = Time.time + nextFireTime;
   CalculateAimError();

   ...
}

The CalculateAimError() produce compile error because there is a syntax error there:

You wrote:

aimError = Random.Range[-errorAmount, errorAmount];

It should be:

aimError = Random.Range(-errorAmount, errorAmount);

I am very sure that this is a script from the Unity Cookie Tower Defense tutorial. You should have post your question there, or at the very least, try to pause the video and look for the difference between the tutorial script and your script.

private var nextFireTime : float;
private var nextMoveTime : float;
private var desiredRotation : Quaternion;
private var aimError : float;

i am not having much knowledge about javascript but are you sure the above thing will work??? you are directly passing datatype instead of the variable… so according to me it should be like below

private var nextFireTime : your variable name which is holding the value;
private var nextMoveTime : same here ;
private var desiredRotation : same here;
private var aimError : same here;

Don’t forget to mark the answer if found useful…cheers…

Try this:

var target : Transform;

function Update () {
	
	// Rotate towards target    
	var targetPoint = target.position;
	targetPoint.y = transform.position.y;
	
	var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
	transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
}