Making enemies move while shooting player.

I have followed this tutorial to make robots and make them shoot:
http://unity3d.com/support/old-resources/tutorials/fpstutorial

I tried outcommenting everything that seemed logical to make the robots move while they shoot. But I cant seem to find any clue. Right now they stop everytime the robot is close to a player to shoot.

basically what happens is this.
function AttackPlayer () {
var lastVisiblePlayerPosition = target.position;
while (true) {
if (Vector3.Distance(transform.position, target.position) < attackRange) {
var hit : RaycastHit;
if (Physics.Linecast (transform.position, target.position, hit))
hit.transform == target;

// Target is dead - stop hunting
if (target == null)
return;

// Target is too far away - give up
var distance = Vector3.Distance(transform.position, target.position);
// Debug.Log(distance + “>” + (shootRange * 3));
if (distance > shootRange * 3)
return;

lastVisiblePlayerPosition = target.position;
RotateTowards(target.position);

var forward = transform.TransformDirection(Vector3.forward);
var targetDirection = lastVisiblePlayerPosition - transform.position;
targetDirection.y = 0;
// Debug.Log(distance + “<” + shootRange + " " + angle + “<” + shootAngle);

// Start shooting if close and play is in sight
if (distance < shootRange)
yield StartCoroutine(“Shoot”);
}

And the shoot is :

function Shoot () {
// Start shoot animation
animation.CrossFade(“shoot”, 0.3);

// Wait until half the animation has played
yield WaitForSeconds(delayShootTime);

// Fire gun
BroadcastMessage(“Fire”);

// Wait for the rest of the animation to finish
yield WaitForSeconds(animation[“shoot”].length - delayShootTime);
}

Where is the script that moves the bots and plays the walk animation?

Good to see your going through the tutorials. So many new comers think there going to create WoW or CoD8 futuristic warrior on there first day lol.

LoL :slight_smile:

The script that makes them move is here:

function MoveTowards (position : Vector3) {
var direction = position - transform.position;
direction.y = 0;
if (direction.magnitude < 0.5) {
SendMessage(“SetSpeed”, 0.0);
return;
}

// Rotate towards the target
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);

// Modify speed so we slow down when we are not facing the target
var forward = transform.TransformDirection(Vector3.forward);
var speedModifier = Vector3.Dot(forward, direction.normalized);
speedModifier = Mathf.Clamp01(speedModifier);

// Move the character
direction = forward * speed * speedModifier;
GetComponent (CharacterController).SimpleMove(direction);

SendMessage(“SetSpeed”, speed * speedModifier, SendMessageOptions.DontRequireReceiver);
}

As I have seen in the AI.js. This is used to choose waypoints. It was also used in the attackplayer function. But I removed the move toward there. But it still moves toward the player and just stand there shooting at me :S